快捷搜索: 王者荣耀 脱发

统计不同字符个数----Python

描述

用户从键盘输入一行字符。请编写一个程序,统计并输出其中英文字符、数字符号、空格和其他字符的个数。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬

输入格式

输入一个一行字符‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬

输入使用input(),不要增加额外的提示信息‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬

输出格式

所统计的各种字符的个数‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬

输入输出示例

输入 输出 示例 1 Qwert 123; k0987_, 6 7 2 5
n=input()
n=list(n)
e=0
num=0
k=0
q=0
for i in range(len(n)):
    if(n[i]>=a and n[i]<=z or n[i]>=A and n[i]<=Z):
        e+=1
    elif(n[i]== ):
        k+=1
    elif(n[i]>=0 and n[i]<=9):
        num+=1
    else:
        q+=1
print("{} {} {} {}".format(e,num,k,q))
s=input()
letters=0
digits=0
spaces=0
others=0
for ch in s:
    if ch>=a and ch<=z or ch>=A and ch<=Z:
        letters+=1
    elif ch>=0 and ch<=9:
        digits+=1
    elif ch== :
        spaces+=1
    else:
        others+=1
print(letters,digits,spaces,others)
经验分享 程序员 微信小程序 职场和发展