问题描述
编写函数 number,接收一个字符串,分别统计大写字母、小写字母、数字、其他字符的个数,并以元组的形式返回结果。
并编写主程序调用该函数。 主调程序如下:
s = input()
print(demo(s))
样例输入:Hello World!
样例输出:(2, 8, 0, 2)
解答
def demo(n):
NUM=num=digit=other=0
for i in n:
if 'A'<=i<='Z':
NUM=NUM+1
elif 'a'<=i<='z':
num=num+1
elif '0'<=i<='9':
digit=digit+1
else:
other=other+1
return(NUM,num,digit,other)
s = input()
print(demo(s))