在这节课中,豁然开朗,懂得了各种函数的使用。
这是上课做的练习,可以清晰所有代码的意思
#计数.py(P104_3_1)
#I
Str=input('请输入一段字符:')
char=0
space=0
num=0
other=0
#P
for i in Str :
if ((i>'A' and i<'Z') or (i>'a' and i<'z')): #查找字母
char=char+1 #字母个数累加(char+=1,char=char++)
elif (i==''): #查找空格
space=space+1
elif (i>'0' and i<'9'): #查找数字
num=num+1
else: #查找其他内容
other=other+1
#O
print('字母: %d'%char)
print('空格: %d'%space)
print('数字: %d'%num)
print('其他: %d'%other)