我的意思是在“!”之后停止读取输入。出现。这是我的代码的一部分:
msg = input("What is your message? ")
print()
lett = 0
otherch = 0
num_vowels = 0
num_consanants = 0
count_character = [0] * 100000
for character in msg.upper():
if character == "!":
print("lett =", lett)
print("other char = ", otherch)
print("num_vowels = ", num_vowels)
print("num_consanants = ", num_consanants)
elif character < "A" or character > "Z":
otherch = otherch + 1
count_character[ord(character)] = count_character[ord(character)] + 1
else:
lett = lett + 1
count_character[ord(character)] = count_character[ord(character)] + 1
for character in msg.upper():
print("character", character, "appeared" , count_character[ord(character)] , "times")
但是,如果我运行程序并输入诸如“hello!hi”之类的内容,它会继续读取感叹号后的文本,并继续说输入中有两个 H 和一个 I。有帮手吗?