[英]Why does not `input` show up on python?
I am making simple game which there are 2 players and 20 sticks given. 我正在做一个简单的游戏,有2个玩家和20个棍棒。 Each player can pick 1-3 stick(s) and player picks last stick will lose the game.
每个玩家可以选择1-3个杆,而玩家选择最后一个杆将输掉比赛。
def stix(num):
for _ in range(5): print('| '* num)
print
stix(20)
game_over = 0
while game_over !=0:
players={}
for i in range(2):
players[i] = int(input('Player %d: Please pick stick(s) up to 3' %i))
if players > 3 or players<0:
print('Please pick between 1 - 3 stick(s)')
else:
stix-=players
if stix <= 0:
print('Player[i] lost')
break
else:
print('There is %d stick(s) left' %stix)
print(stix-players[i])
So, function stix
shows 20 sticks and that's it. 因此,功能
stix
显示20条,仅此而已。 It does not ask please pick stick(s) up to 3
. 它不要求
please pick stick(s) up to 3
。 What did I miss in here? 我在这里想念什么?
*I am using python 2.6 *我正在使用python 2.6
Thanks in advance! 提前致谢!
You're never entering the while loop at all: 您根本不会进入while循环:
game_over = 0
while game_over !=0: # Evaluated to false the first time so it's skipped.
# code
So the error, in this case, has nothing to do with input()
因此,在这种情况下,错误与
input()
无关
Your while case is that "game_over" does not equal 0 but the line directly above it sets it to 0. 您的while情况是“ game_over”不等于0,而是直接位于其上方的行将其设置为0。
I think what you want is: 我认为您想要的是:
game_over = True
while not game_over:
...
Your problem is that your while
loop is going to run while game_over is not 0, but in the line before, you set game_over
to 0. 您的问题是当game_over 不为 0时,您的
while
循环将运行,但是在前面的一行中,您将game_over
设置为0。
game_over = 0
while game_over !=0:
...
Thus, change game_over
to 1, and your code will work! 因此,将
game_over
更改为1,您的代码将起作用!
def stix(num):
for _ in range(5): print('| '* num)
print
stix(20)
game_over = 1
while game_over !=0:
players={}
for i in range(2):
players[i] = int(input('Player %d: Please pick stick(s) up to 3' %i))
if players > 3 or players<0:
print('Please pick between 1 - 3 stick(s)')
else:
stix-=players
if stix <= 0:
print('Player[i] lost')
break
else:
print('There is %d stick(s) left' %stix)
print(stix-players[i])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.