【问题描述】从键盘输入一个字符串,分别统计数字,字母(包括大小写)和其他字符的个数,输出每个字符及其个数。要求:用字典进行统计。
【输入形式】输入一个随机字符串
【输出形式】输出为记录统计的结果,保持数字、字母、其他的顺序
【样例输入】afahiubuio.,.,1.,4.1
【样例输出】数字3,字母8,其他9
【样例说明】
【评分标准】
a = input() b = len(a) n = {"数字": 0, "字母": 0, "其他": 0} word = [] math = [] other = [] for i in range(0, b): l = a[i].isalpha() # 字母 m = a[i].isdigit() # 数字 if l == True: word.append(a[i]) else: if m == True: math.append(a[i]) else: other.append(a[i]) d = len(word) f = len(math) g = len(other) if f != 0: n["数字"] = f print("数字{}".format(n["数字"]), end=",") if d != 0: n["字母"] = d print("字母{}".format(n["字母"]), end=",") if g != 0: n["其他"] = g print("其他{}".format(n["其他"]), end="")a = input() b = len(a) n = {"数字": 0, "字母": 0, "其他": 0} word = [] math = [] other = [] for i in range(0, b): l = a[i].isalpha() # 字母 m = a[i].isdigit() # 数字 if l == True: word.append(a[i]) else: if m == True: math.append(a[i]) else: other.append(a[i]) d = len(word) f = len(math) g = len(other) if f != 0: n["数字"] = f print("数字{}".format(n["数字"]), end="") if d != 0: n["字母"] = d print(",字母{}".format(n["字母"]), end="") if g != 0: n["其他"] = g print(",其他{}".format(n["其他"]), end="")