I'm a beginner at using python in wing ide and I'm trying to write a slot machine program. It is not running properly, it keeps on repeating 2 statements, here's the output I get when I input "100":
Slot Machine You have 1000 coins. Press 0 to exit, any other number to play that coins per spin. 100 8 5 3 You lost 100 . You now have 900 coins. Press 0 to exit, any other number to play that coins per spin. You have 900 coins. Press 0 to exit, any other number to play that coins per spin.
-it repeats "Press 0 to exit, any other number to play that coins per spin." and "You have () coins."
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.",
I think this is a great opportunity for you to begin to try out debuggers in your IDE of choice. Try to step through the code to see the execution. Stepping through the code will also afford you the opportunity to see many nuances and learn along the way.
Most importantly, don't forget to document what your problems are, the solution(s) and maybe how you arrived at it. You just might not say when you'll need to refer to it again.