首页 > 其他 > 详细

每日一题 2019.9.12

时间:2019-09-12 11:54:33      阅读:88      评论:0      收藏:0      [点我收藏+]
 # 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 如有不足请多多指教

每日一题 2019.9.12

原文:https://www.cnblogs.com/walxt/p/11510837.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!