A40080. 编写程序帮老师对英语试卷中的英文字母、 数字和其他字符(注意: 包括空格) 进行分类并统计每种字符的数量。输入样例:**Welcome to 2023~!输出样例:字母: Welcometo,共 9 个数字: 2023,共 4 个其它字符:** ~!,共 6 个
填空题
较易
知识点
题目描述
编写程序帮老师对英语试卷中的英文字母、 数字和其他字符(注意: 包括空格) 进行分类并统计每种字符的数量。
输入样例:
**Welcome to 2023~!
输出样例:
字母: Welcometo,共 9 个
数字: 2023,共 4 个
其它字符:** ~!,共 6 个
参考答案
s=input()
letter=''
number=''
other=''
for i in s:
if i>='a' and i<='z' or i>='A' and i<='Z':
letter+=i
elif i>='0' and i<='9':
number+=i
else:
other+=i
print('字母: {},共{}个'.format(letter,len(letter)))
print('数字: {},共{}个'.format(number,len(number)))
print('其它字符:{},共{}个'.format(other,len(other)))
上一题
下一题