我試圖檢查輸入函數中輸入的內容是否都是字母字符。基本上我想確保號碼不被輸入。但是,當我鍵入一個數字,例如4時,沒有任何反應。我甚至沒有看到異常錯誤。另外,如果我輸入除「帶寶貝」或「開門」之外的任何內容,則不會啓動bear_room功能。 Haaalp。提前致謝!python 3:嘗試除非沒有工作檢查isalpha函數
def bear_room():
print("there's a bear here")
print("the bear has a bunch of honey")
print("the fat bear is front of another door")
print("how are you going to move the bear?")
choice = str(input("(Taunt bear, take honey, open door?: "))
try:
if choice.isalnum() == False:
if choice == "take honey":
print("the bear looks at you then slaps your face off")
elif choice == "open door":
print("get the hell out")
else:
bear_room()
except Exception as e:
print(str(e))
print("numbers are not accepted")
bear_room()
bear_room()
謝謝,我過去認爲這個過程。 – eric