我是在wing ide中使用python的初学者,我正在尝试编写一个老虎机程序。它运行不正常,不断重复 2 条语句,这是我输入“100”时得到的输出:
老虎机 你有 1000 个硬币。按 0 退出,任何其他数字在每次旋转时播放该硬币。100 8 5 3 你输了 100 。你现在有 900 个硬币。按 0 退出,任何其他数字在每次旋转时播放该硬币。你有900个硬币。按 0 退出,任何其他数字在每次旋转时播放该硬币。
- 它重复“按 0 退出,任何其他数字在每次旋转时播放该硬币。” 和“你有()个硬币。”
import random
coins = 1000
wager = 2000
print "Slot Machine"
while coins > 0:
print "You have",coins, "coins."
print "Press 0 to exit, any other number to play that coins per spin."
wager = input("")
if coins == 0:
break
while wager>coins:
print "Your Wager is greater than the number of coins you have.",
wager = input("")
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 or x == 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 lost" ,wager,". You now have", coins, "coins."
print "Press 0 to exit, any other number to play that coins per spin.",