我是在wing ide中使用python的初学者,我正在尝试编写一个老虎机程序。它运行不正常,我知道它与无限循环有关,但我不确定如何修复该循环以使代码正常运行。有任何想法吗?
import random
coins = 1000
wager = 2000
print "Slot Machine"
print "You have",coins, "coins."
print "Press 0 to exit, any other number to play that coins per spin."
while wager>coins:
print "Your Wager is greater than the number of coins you have.",
wager = input("")
while ((coins>0) and (wager!= 0)):
x = random.randint(0,10)
y = random.randint(0,10)
z = random.randint(0,10)
print x,
print y,
print z
if (x==y) and (x==z):
coins = (coins + wager)*100
print "You won",wager*100,". You now have" , coins, "coins per spin."
print "Press 0 to exit, any other number to play that many coins per spin."
elif (x==y and x==z) or (x!=y and x==z) or (x!=y and y==z):
coins = coins + wager*10
print "You won" ,wager*10,". You now have", coins, "coins."
print "Press 0 to exit, any other number to play that coins per spin."
else:
coins = coins - wager
print "You won" ,wager,". You now have", coins, "coins."
print "Press 0 to exit, any other number to play that coins per spin.",
wager = input("")
while wager>coins:
print "Your Wager is greater than the number of coins you have.",
wager = input("")