|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
def count(str1):
flag_alpha = 0
flag_digit = 0
flag_space = 0
flag_other = 0
for a in str1:
if a.isalpha():
flag_alpha += 1
for b in str1:
if b.isdigit():
flag_digit += 1
for c in str1:
if c.isspace():
flag_space += 1
for d in str1:
if (not a.isalpha()) and (not d.isdigit()) and (not d.isspace()):
flag_other += 1
print('字符串共有: 英文字母%d个,数字%d个,空格%d个,其他字符%d个!' % (flag_alpha, flag_digit, flag_space, flag_other))
str1 = input('请输入一个字符串:')
count(str1)
统计一个参数的代码写出来了, 貌似可以运行
|
|