それぞれの文字の入力ライン(20文字以上)、その中に文字、スペース、数字および他の文字の数を数えることができます。
結果は次の通りです:
文字列を入力してください:45se R、d5d〜S58 *
手紙= 6、4 =スペース、数= 5、その他= 3
s=input('请输入一个字符串:\n')
letters=0
space=0
digit=0
others=0
for c in s:
if c.isalpha():
letters+=1
elif c.isspace():
space+=1
elif c.isdigit():
digit+=1
else:
others+=1
print('英文字母=%d 个,空格=%d 个,数字=%d 个,其他=%d 个'%(letters,space,digit,others))