2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > python每日一练:输入一个字符串 统计其中的小写字母 大写字母 空格键 以及其它字

python每日一练:输入一个字符串 统计其中的小写字母 大写字母 空格键 以及其它字

时间:2018-09-09 21:16:49

相关推荐

python每日一练:输入一个字符串 统计其中的小写字母 大写字母 空格键 以及其它字

a = str(input())smallword = 0bigword = 0number = 0blank = 0others = 0longth = len(a) #记录字符串的长度,后面用于遍历次数#i作为字符串中的具体字符参加遍历for i in a:#若i在‘abcdefghijklmnopqrstuvwxyz’里面则小写字母加1if i in 'abcdefghijklmnopqrstuvwxyz' :smallword = smallword + 1if i in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' :bigword = bigword + 1if i in ' ':blank = blank + 1others = longth - smallword -bigword - blankprint(' 小写字母 :',smallword,' 大写字母 :',bigword,' 空格键 :',blank,' 其它字符: ',others)

python每日一练:输入一个字符串 统计其中的小写字母 大写字母 空格键 以及其它字符 并在一行内输出统计的个数

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。