每日一题 2019.9.12

 # coding=utf-8
import string
"""输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。"""

strInput = input("please input the string:")

letters = 0
spaces = 0
digits = 0
others = 0

for test in strInput:
    if test.isalpha():
        letters += 1
    elif test.isdigit():
        digits += 1
    elif test.isspace():
        spaces += 1
    else:
        others += 1

print("字母:{0},数字{1},空格{2},其他字符{3}".format(letters,digits,spaces,others)) 
 
# 初学Python 如有不足请多多指教
posted @ 2019-09-12 11:11  雪瞳  阅读(146)  评论(0编辑  收藏  举报