我需要代码能够接受整数和字符串版本1和2.我尝试在输入()上使用str()和int()但它不起作用,只接受整数形式1和2.如果用户的输入不是1,1,2或2,我需要退出游戏.任何帮助表示赞赏.
print ('\n If you want to play the first game, enter 1.')
print ('I you want to play the second game, enter 2.')
gamechoice = str(int(input('\nPlease select the difficulty of the game: '))).lower()
if gamechoice == 1 or 'one':
Firstgame()
elif gamechoice == 2 or 'two':
secondgame()
else:
print ('\nSorry i dont undrstand')
sys.exit(0)
Run Code Online (Sandbox Code Playgroud)