The problem description is as follows:
Enter an article and count the number of characters (letters), numbers, spaces and special characters in the article. Use isalpha(), isdigit(), isspace() functions to implement.
The program code is as follows:
tmpStr = input('请输入文章:')
alphaNum=0
numbers=0
spaceNum=0
otherNum=0
for i in tmpStr:
if i.isalpha():
alphaNum +=1
elif i.isdigit():
numbers +=1
elif i.isspace():
spaceNum +=1
else:
otherNum +=1
print('字母=%d'%alphaNum)
print('数字=%d'%numbers)
print('空格=%d'%spaceNum)
print('其他=%d'%otherNum)
The result of the program running is as follows:
Friends who see this, don’t forget to like it before leaving!
Follow bloggers to learn more about Python programming knowledge!