在一行上输入一个长度为
的字符串。
第一行输出一个整数,代表字符串中英文字母的个数。
第二行输出一个整数,代表字符串中空格的个数。
第三行输出一个整数,代表字符串中数字的个数。
第四行输出一个整数,代表字符串中其它字符的个数。
1qazxsw23 edcvfr45tgbn hy67uj m,ki89ol.\\/;p0-=\\][
26 3 10 12
words = input() result = [0,0,0,0] for word in words: if ord(word)>=48 and ord(word)<=57: result[2] += 1 elif ord(word)>=65 and ord(word)<=90&nbs***bsp;ord(word)>=97 and ord(word)<=122: result[0] += 1 elif ord(word) == 32: result[1] += 1 else: result[3] += 1 for i in result: print(i)
while True: try: s = input() letters = spaces = digits = others = 0 for c in s: letters += c.isalpha() spaces += c.isspace() digits += c.isdigit() others += not (c.isalpha()&nbs***bsp;c.isspace()&nbs***bsp;c.isdigit()) print(letters, spaces, digits, others, sep='\n') except: break
def main(): s = input() letters = [] # 存储英文字母 spaces = [] # 存储空格 digits = [] # 存储数字 others = [] # 存储其他字符 for char in s: if char.isalpha(): letters.append(char) elif char.isspace(): spaces.append(char) elif char.isdigit(): digits.append(char) else: others.append(char) print(len(letters)) # 输出英文字母的个数 print(len(spaces)) # 输出空格的个数 print(len(digits)) # 输出数字的个数 print(len(others)) # 输出其他字符的个数 if __name__ == "__main__": main()
""" from numpy import s_ 统计各个字符的数量,有两种方法 1. 正则匹配 2. 使用count """ s = input() # 找出元 s_sole = list(set(list(s))) letter_count = 0 space_count = 0 num_count = 0 other_count = 0 for letter in s: if letter.isalpha(): letter_count += 1 elif letter.isdigit(): num_count += 1 elif letter == ' ': space_count += 1 else: other_count += 1 print(letter_count) print(space_count) print(num_count) print(other_count)
st = input() c1 = 0 c2 = 0 c3 = 0 c4 = 0 for i in st: if i.isalpha(): c1 += 1 elif i == ' ': c2 += 1 elif i.isnumeric(): c3 += 1 else: c4 += 1 print(c1) print(c2) print(c3) print(c4)
upper_alphabet = [chr(i) for i in range(ord('A'),ord('Z')+1)]
lower_alphabet = [chr(i) for i in range(ord('a'),ord('z')+1)]
numbers = [str(i) for i in range(10)]
input_str = input()
alphabet_num = 0
space_num = 0
number_num = 0
others_num = 0
for c in input_str:
if c in (upper_alphabet + lower_alphabet):
alphabet_num += 1
elif c == ' ':
space_num += 1
elif c in numbers:
number_num += 1
else:
others_num += 1
print(alphabet_num)
print(space_num)
print(number_num)
print(others_num) string = input() count_alpha = 0 count_blank = 0 count_digit = 0 count_other = 0 for code in string: if code.isalpha(): count_alpha += 1 elif code == ' ': count_blank += 1 elif code.isdigit(): count_digit += 1 else: count_other += 1 print(count_alpha) print(count_blank) print(count_digit) print(count_other)