#Python 3.6(32-bit)
代码如下:
str = input("please input a string from your keyboard:") # 用户输入字符
eng=num=bla=oth=0
for i in str: #判断字符类型
if (ord(i)>=97 and ord(i)<=122) or (ord(i)>=65 and ord(i)<=90):
eng=eng+1
elif ord(i)>=48 and ord(i)<=57:
num=num+1
elif ord(i)==32:
bla=bla+1
else:
oth=oth+1
print("英文字母个数:{}个".format(eng))
print("数字个数:{}个".format(num))
print("空格个数:{}个".format(bla))
print("其他字符个数:{}个".format(oth))
本文介绍了一段Python代码,该代码能够统计用户输入的任意字符串中英文字符、数字、空格以及其他字符的数量。

7367

被折叠的 条评论
为什么被折叠?



