首页 > 编程语言 > 详细

python--字符串练习

时间:2020-01-02 12:39:55      阅读:75      评论:0      收藏:0      [点我收藏+]

输??个字符串,要求判断在这个字符串中?写字?,?写字?,数字, 其它字符共出现了多少次,并输出

-*- coding:utf-8 -*-
content = input(请输入一个字符串:)
index = 0
content_len = len(content)
num_count = 0
upper_str_count = 0
lower_str_count = 0
other_count = 0
while True:
    if index >= content_len:
        break
    else:
        val = content[index]
        if val.isdigit():
            num_count += 1
        elif val.isupper():
            upper_str_count += 1
        elif val.islower():
            lower_str_count +=1
        else:
            other_count += 1
    index += 1
message = ‘‘‘
==============输入字符串信息:%s=================
            大写字母出现了 %d次
            小写字母出现了 %d次
                数字出现了 %d次
            其它字符出现了 %d次
==============================================
‘‘‘
print(message %(content,upper_str_count,lower_str_count,num_count,other_count))

 

python--字符串练习

原文:https://www.cnblogs.com/python-cat/p/12131751.html

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