输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数

mac2022-06-30  145

# 题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 from pip._vendor.distlib.compat import raw_input str = raw_input("请输入待统计字符串:") letters = 0 space = 0 digit = 0 others = 0 for i in str: if i.isdigit(): digit += 1 elif i.isspace(): space += 1 elif i.isalpha(): letters += 1 else: others += 1 print ('char = %d,space = %d,digit = %d,others = %d' % (letters,space,digit,others))

转载于:https://www.cnblogs.com/bilaisheng/p/10211058.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)