def Count():
str1=input(‘请输入一个字符串:’)
letter=0 #英文字母
space=0 #空格
digit=0 #数字
other=0 #其他字符
for i in str1:
if(i>=’a’ and i<='z') or (i>=’A’ and i<='Z'):
letter+=1
elif(i==' '):
space+=1
elif(i>=’0′ and i<='9'):
digit+=1
else:
other+=1
print('字母',letter,'个,数字',digit,'个,空格',space,'个,其他字符',other,'个')
Count()
本文由作者笔名:逗号CMS 于 2024-08-20 23:45:01发表在本站,原创文章,禁止转载,文章内容仅供娱乐参考,不能盲信。
本文链接: http://www.lovelp.cn/wen/132101.html