Ok so I am making a roulette game. The random number that the spinner lands on is called ‘figure’. It is a very basic and simple code but it won’t seem to work for me properly.
At the moment you either pick a specific number or choose 1 – 18. I’ve tried many different ways and still no luck. Here is my code. If anyone knows what the problem is please let me know. Thanks:
numbers = ['1', '2', '3'.......'35', '36']
figure = choice(numbers)
d = textinput("Pick bet", "")
if int(figure) > 18 and d == '1-18' or '1 - 18' or '1- 18' or '1 -18':
pu()
goto(100,100)
write("Loser", font = ("Comic Sans MS", 30, "bold"))
elif int(figure) < 19 and d == '1-18' or '1 - 18' or '1- 18' or '1 -18':
pu()
goto(10,100)
write("Well done", font = ("Comic Sans MS", 30, "bold"))
elif int(d) in range(36) and int(figure) == int(d):
pu()
goto(100,100)
write("Well done", font = ("Comic Sans MS", 30, "bold"))
elif int(d) in range(36) and int(figure) != int(d):
pu()
goto(100,100)
write("Loser", font = ("Comic Sans MS", 30, "bold"))
Look at:
Here you have several statements that always evaluate to True; each of
'1 - 18' or '1- 18' or '1 -18'is a a non-empty string. It doesn’t matter what valuesint(figure)ordhave. This means python sees that line as the equivalent ofif something or True.What you want to do instead is use the
inoperator to test if yourdis part of a list of options:The same problem applies to your
elifstatement.