# 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
# 13 回车
# 32 空格
# 48-57 数字是字符串的
# 65-90 A-Z
# 97-122 a-z
# ord(a)a转为acsii
# chr(b)b对应的字符为
# ================================
# content = 'dkahlt'
# for i in range(len(content)):
# con2 = content[i]
# print(con2)
# # 以上几行等价于for i in contert:
# for i in content:
# print(i)
# =================================
print('first'.center(40,'='))
content = input('Please enter some content:')
al = 0
tb = 0
dig = 0
other = 0
for i in range(len(content)):
con2 = ord(content[i])
if (con2 >= 65 and con2 <= 90) or (con2 >= 97 and con2 <= 122):
al += 1
elif con2 == 32:
tb += 1
elif(con2 >= 48 and con2 <= 57):
dig += 1
else:
other += 1
print('英文字母个数为{}个、空格个数为{}个、数字个数为{}个、其它字符的个数为{}个'.format(al,tb,dig,other))
print('second'.center(40,'='))
import re
content = input('Please enter some content:')
al = 0
tb = 0
dig = 0
other = 0
for i in content:
if re.match('[A-Za-z]',i) != None:
al += 1
elif re.match('[\s]',i) != None:
tb += 1
elif re.match('[\d]',i) != None:
dig += 1
else:
other += 1
print('英文字母个数为{}个、空格个数为{}个、数字个数为{}个、其它字符的个数为{}个'.format(al,tb,dig,other))# 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
# 13 回车
# 3