题目:
输入一行字符 分别统计出其英文字母、空格、数字和其他字符的个数
#大写字母
capital = 0
#小写字母
lowercase = 0
#数字
number = 0
#空格
space = 0
#其他
other = 0
word = list(input('请输入任意字符:'))
for i in word:
if i.isalpha() and i.isupper():
capital += 1
elif i.isalpha() and i.islower():
lowercase += 1
elif i.isdigit():
number += 1
elif i.isspace():
space += 1
else:
other += 1
print('大写英文字母为%s个' % capital)
print('小写英文字母为%s个' % lowercase)
print('数字为%s个' % number)
print('空格为%s个' % space)
print('其他字符为%s个' % other)
本文介绍了一个简单的字符统计程序,能够区分并计数输入字符串中的大写字母、小写字母、数字、空格及其他字符的数量。
954

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



