7-1 统计大写字母、小写字母、数字
编写函数,接收一个字符串,分别统计大写字母、小写字母、数字、其他字符的个数,并以元组的形式返回结果。
输入格式:
输入一字符串s。
输出格式:
以元组形式输出大写字母、小写字母、数字、其他字符的个数。
输入样例:
在这里给出一组输入。例如:
Abcd3g,t4.BC4
结尾无空行
输出样例:
在这里给出相应的输出。例如:
(3, 5, 3, 2)
结尾无空行
def demo(v):
small = big = digit = other =0
for i in v:
if 'A'<=i<='Z':#判断它是否为大写字母
big+=1
elif 'a'<=i<='z':#判断是否为小写字母
small+=1
elif '0'<=i<='9':#判断是否为数字
digit+=1
else:
other+=1
return (big,small,digit,other)将所得到的值返回
x =input()
print(demo(x),end="")#在这边注意的是,结尾无空行