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

来源:互联网 发布:python snmp开发教程 编辑:程序博客网 时间:2024/06/11 16:53
# 题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。from pip._vendor.distlib.compat import raw_inputstr = raw_input("请输入待统计字符串:")letters = 0space = 0digit = 0others = 0for i in str:    if i.isdigit():        digit += 1    elif i.isspace():        space += 1    elif i.isalpha():        letters += 1    else:        others += 1print ('char = %d,space = %d,digit = %d,others = %d' % (letters,space,digit,others))
阅读全文
0 0