#🔒 Casino Program outputting wrong answer

29 messages · Page 1 of 1 (latest)

indigo vale
#

I am making this casino game and even if the roulette wheel lands on an odd number it says that it is even

`import random

global money
money = 50

def main():
even = []
odd = []
while True:
print(f"money: £{money}")
print("Select a Game!")
game = input("1: Roulette, 2:Blackjack, 3:Poker\n")
if game == "1":
roulette(money, odd, even)
break
elif game == "2":
blackjack()
break
elif game == "3":
poker()
break
else:
pass

def odd_even(x):
even = []
odd = []
while x <= 36:
if (x % 2) == 0:
even.append(x)
x = x+1
else:
odd.append(x)
x = x + 1
print(odd)
return odd
return even

def roulette(money, odd, even):
print("You selected Roulette")
bet = input("Select Bet: 0-36, Odd, Even, Black, Red\n")
if bet == "0" or "1" or "2" or "3" or "4" or "5" or "6" or "7" or "8" or "9" or "10" or "11" or "12" or "13" or "14" or "15" or "16" or "17" or "18" or "19" or "20" or "21" or "22" or "23" or "24" or "25" or "26" or "27" or "28" or "29" or "30" or "31" or "32" or "33" or "34" or "35" or "36":
try:
bet = int(bet)
except ValueError:
"This is wrong"
else:
pass
cash = int(input("Select bet amount:"))
money = money - cash
x = random.randrange(0,36)
odd_even(x)
if x == 0:
print("number was 0")
else:
odd_even(x)
print (f"Spin was: {x}")
if bet == "odd":
if x in odd:
print("You Win £20")
money = money + 20
print(f"You now have: £{money}")
else:
print("This is even?")
print(odd)

def blackjack():
print("You selected Blackjack")

def poker():
print("You selected Poker")

main()`

sharp gorgeBOT
#

@indigo vale

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

calm orchid
#

!or

sharp gorgeBOT
#
The or-gotcha

When checking if something is equal to one thing or another, you might think that this is possible:

# Incorrect...
if favorite_fruit == 'grapefruit' or 'lemon':
    print("That's a weird favorite fruit to have.")

While this makes sense in English, it may not behave the way you would expect. In Python, you should have complete instructions on both sides of the logical operator.

So, if you want to check if something is equal to one thing or another, there are two common ways:

# Like this...
if favorite_fruit == 'grapefruit' or favorite_fruit == 'lemon':
    print("That's a weird favorite fruit to have.")

# ...or like this.
if favorite_fruit in ('grapefruit', 'lemon'):
    print("That's a weird favorite fruit to have.")
indigo vale
calm orchid
#
  • functions can only return once - the second return statement in odd_even isn't doing anything
  • you are not using the return value of odd_even at all
  • avoid using globals
  • else: pass is doing nothing
calm orchid
indigo vale
indigo vale
calm orchid
indigo vale
haughty torrent
sharp gorgeBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

haughty torrent
indigo vale
haughty torrent
#

you were supposed to change the line

indigo vale
haughty torrent
#

!e ```py
[print(i) for i in range(10)]

sharp gorgeBOT
#

@haughty torrent :white_check_mark: Your 3.12 eval job has completed with return code 0.

001 | 0
002 | 1
003 | 2
004 | 3
005 | 4
006 | 5
007 | 6
008 | 7
009 | 8
010 | 9
haughty torrent
#

first 10 numbers (starting from 0)

indigo vale
#

ye but they need to be strings

haughty torrent
#

!e py print([str(i) for i in range(10)])

sharp gorgeBOT
#

@haughty torrent :white_check_mark: Your 3.12 eval job has completed with return code 0.

['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
haughty torrent
#

see

sharp gorgeBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.