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