Python3 statistics string, multiplication formula example

Source: Internet
Author: User

1. Statistics string (Python3)

Title: Enter a character and compile statistics for the number of letters, spaces, numbers, and other characters.

1. Program Analysis: Using the while statement, the condition of the input character is not ' \ n '

IsDigit () Determine if it is a number

Isalpha () to determine if it is a letter

Isalnum () Determine if it is a combination of letters and numbers

#!/usr/bin/env python# -*- coding:utf-8 -*-#  @Time:   2018-01-24  11:40#  @Author: feng xiaoqing#  @File:    string.pystatus = 1while  status:    string = input ("please input a string (' Quit ' would  exit) (:  ")     if string ==  ' quit ':         exit (1)     disgit = pha = space = other  = 0    for i in string:         if i.isdigit ():             disgit  += 1        elif i.isalpha ():             pha += 1         elif i.isspaCE ():            space += 1         else:             other += 1    print ("number: {0}, Letter: {1}, Space: {2}, other: {3}". Format (Disgit,pha,space, Other))

2. Multiplication formula (Python3)

Multiplication formula:


#!/usr/bin/env python# -*- coding:utf-8 -*-#  @Time:   2018-01-24  11:57#  @Author: feng xiaoqing#  @File:    chengfakoujue.pyfor i in  range (1,10):  #行     for j in range (1,i+1):         chengji = i*j        print ("{0 } x {1} = {2}   ". Format (J,i,chengji), end=")     print () or: for  i in range (1,10):     for j in range (1,i+1):         chengJi = i*j         Print ("{0} x {1} = {2}  ". Format (J,i,chengji), end= ")          if i == j:             print ()


Python3 statistics string, multiplication formula example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.