程序:
letter_num = 0 blank_num = 0 figure_num = 0 other_num = 0 a = input('请输入一行字符:') for i in a: if i.isalpha(): letter_num += 1 elif i.isspace(): blank_num += 1 elif i.isdigit(): figure_num += 1 else: other_num += 1 print("输入的字符中,字母的个数为{0},空格的个数为{1},数字的个数为{2},其他字符的个数为{3}".format(letter_num, blank_num, figure_num, other_num))
结果:
请输入一行字符:vrd15 *&$ji4 张 佰 威 jiu7gr8
输入的字符中,字母的个数为13,空格的个数为5,数字的个数为5,其他字符的个数为3