输入一个字符串,然后统计其长度,包含的数字、小写字母、大写字母和特殊字符的位数并输出。
import string
def SlowSnail(s):
up = 0
low = 0
space = 0
digit = 0
others = 0
for c in s:
if c.isupper():
up += 1
elif c.islower():
low += 1
elif c.isspace():
space += 1
elif c.isdigit():
digit += 1
else:
others += 1
print('大写字母 = %d,小写字母 = %d,空格 = %d,数字 = %d,其他 = %d' % (up, low, space, digit, others))
while 1:
s = input('请输入一个字符串:\n')
if '-1' in s: # 设置退出循环条件
break
SlowSnail(s) # 调用函数
import re
a = input()
print(len(a))
b = []
for i in a:
if re.match(r"\S",i) !=None:
b.append((i,a.index(i)))
print(b)