当我输入“N”或“n”时,我不明白为什么函数会返回正确的字母。当我输入不正确的字母时,该函数被调用但返回“无”。该函数应该保持循环直到输入正确的字母。
这是我输入正确字母时的输出。
(N)ew game
Your choice?: n
Your choice before returning the value to main: n
Your choice: n
这是我输入错误字母时的输出。
(N)ew game
Your choice?: j
Wrong input
(N)ew game
Your choice?: n
Your choice before returning the value to main: n
Your choice: None
源代码:
def auswahl():
print("(N)ew game")
choice = input("Your choice?: ")
if choice == 'N' or choice == 'n':
print("Your choice before returning the value to main:", choice)
return choice
else:
print("Wrong input")
auswahl()
#main
eingabe = auswahl()
print("Your choice:", eingabe)
大话西游666
相关分类