小编L.T*_*SON的帖子

如何让python 3接受整数和字符串答案

我需要代码能够接受整数和字符串版本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)

python string integer python-3.x

1
推荐指数
1
解决办法
808
查看次数

标签 统计

integer ×1

python ×1

python-3.x ×1

string ×1