# 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

 1 def count(char):
 2     a, b, c, d = 0, 0, 0, 0
 3     for i in char:
 4         if i == " ":
 5             c += 1
 6         elif i.isdecimal():
 7             a += 1
 8         elif i.isalpha():
 9             b += 1
10         else:
11             d += 1
12     return a, b, c, d
13 
14 
15 res = count("sall dsakl5453 djald4853*&$cmak 131*77&65")
16 print(res)

 

posted @ 2021-10-31 22:21  余鑫2020  阅读(245)  评论(0)    收藏  举报