Roulette payout

#Roulette Payouts

import random

lucky_num = random.randint (0, 36)

print ("the lucky number is",lucky_num)


#Defining the colors on the table

green_spaces = 0 and 00
red_spaces = [1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36]
black_spaces = [2,4,6,8,10,11,13,15,17,20,22,24,26,28,29,31,33,35]

#input from the user which type of bet they want

good_input = "single number" or  "red vs black" or "odd vs even" or "1 to 18 vs 19 to 36"

bet_type = input ("Enter what type of bet you want: ")

print (bet_type)

#if bet_type != "single number" or  "red vs black" or "odd vs even" or "1 to 18 vs 19 to 36":
#   print ("the program doesn't play that bet")
if bet_type != good_input:
    bet_type = input ("Enter what type of bet you want: ")

# working on single number bet
elif bet_type == "single number" :
    bet_single_number = input ("enter the number you wish to bet on: ")
    if bet_single_number == red_spaces:
        print ("red has won")
    elif bet_single_number == green_spaces:
        print ("pay 0 or pay 00")
    else:
        print ("black has won")

# working on red vs black bet

elif bet_type == "red vs black":
    bet_color = input ("Enter the color you wish to bet on: " )
    if bet_color == "red" and lucky_num == red_spaces:
        print ("red has won")
    else:
        print ("black has won")

# working on odd vs even
elif bet_type == "odd vs even":
    bet_odd_even = input ("Enter what you bet on, odd or even")
    if lucky_num % 2 == 1:
        print ("odd won")
    elif lucky_num % 2 == 0:
        print ("even won")
    else:
        print ("pay 0 or pay 00")

# working on 1 to 18 vs 19 to 36
elif bet_type == " 1 to 18 vs 19 to 36":
    bet_num = input("Enter the number you wish to bet")
    if bet_num  in range (1,19):
        print (" 1 to 18 won")
    elif bet_num in range (19,37):
        print ("19 to 36 won")

This part of the code is not being recognised, please help

When you say not being recognised what do you mean? Error codes, unintended behaviour?

Since it’s a comparison it’s always worthwhile knowing exactly what you’re comparing so consider using print or similar to start debugging. The name bet_type in particular will not be what you expect.

that part of the code its like its being skipped and not executed, this l am specifically referring to the if statement

so the input statement appears again

If it is not throwing a syntax error then it seems likely the code is running but not doing what you expect. As with the previous message, try a little debugging.

#Roulette Payouts

import random
from itertools import chain, repeat

lucky_num = random.randint (0, 36)

print ("the lucky number is",lucky_num)


#Defining the colors on the table

green_spaces = 0 and 00
red_spaces = [1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36]
black_spaces = [2,4,6,8,10,11,13,15,17,20,22,24,26,28,29,31,33,35]

#input from the user which type of bet they want

good_input = {"single number" or  "red vs black" or "odd vs even" or "1 to 18 vs 19 to 36"}

prompts = chain (["Enter what type of bet you want: "], repeat("try again"))

replies = map(input,prompts)
valid_response = next(filter(good_input.__contains__(replies))

print(valid_response)

#if bet_type != "single number" or  "red vs black" or "odd vs even" or "1 to 18 vs 19 to 36":
#   print ("the program doesn't play that bet")
#if valid_response not in good_input :
    #bet_type = input ("Enter what type of bet you want: ")





# working on single number bet
if valid_response == "single number" :
    bet_single_number = input ("enter the number you wish to bet on: ")
    if bet_single_number == red_spaces:
        print ("red has won")
    elif bet_single_number == green_spaces:
        print ("pay 0 or pay 00")
    else:
        print ("black has won")

# working on red vs black bet

elif valid_response == "red vs black":
    bet_color = input ("Enter the color you wish to bet on: " )
    if bet_color == "red" and lucky_num == red_spaces:
        print ("red has won")
    else:
        print ("black has won")

# working on odd vs even
elif valid_response == "odd vs even":
    bet_odd_even = input ("Enter what you bet on, odd or even")
    if lucky_num % 2 == 1:
        print ("odd won")
    elif lucky_num % 2 == 0:
        print ("even won")
    else:
        print ("pay 0 or pay 00")

# working on 1 to 18 vs 19 to 36
elif valid_response == " 1 to 18 vs 19 to 36":
    bet_num = input("Enter the number you wish to bet")
    if bet_num  in range (1,19):
        print (" 1 to 18 won")
    elif bet_num in range (19,37):
        print ("19 to 36 won")

this is now showing invalid syntax, so l looked at someone else’s code and did the same, while their code worked, mine is showing this error

Slow down a bit; adding bits and pieces of code you don’t understand and hoping it works is like building a jigsaw by just trying every piece to see if it fits. You might even get away with it for very simple tasks but it’ll become exponentially harder the more complex a task you need to accomplish.

I’d highly suggest going back and fixing your own original code so that you understand the steps you’ve taken; I’m not going to help you solve a different problem with every new reply when the old one wasn’t even tried.

Your original comparison is bet_type != good_input. I’m suggesting you check what those two names, bet_type and good_input actually contain before your if statement. Use print, see what they actually contain and work out why it does not behave as you expect.

2 Likes

Ok thanks, let me try that


#Roulette Payouts

import random

lucky_num = random.randint (0, 36)

print ("the lucky number is",lucky_num)


#Defining the colors on the table

green_spaces = 0 and 00
red_spaces = [1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36]
black_spaces = [2,4,6,8,10,11,13,15,17,20,22,24,26,28,29,31,33,35]

#input from the user which type of bet they want

good_input = "single number" ,  "red vs black" , "odd vs even" , "1 to 18 vs 19 to 36"

print (good_input)

bet_type = input ("Enter what type of bet you want: ")

print (bet_type)

#if bet_type != "single number" or  "red vs black" or "odd vs even" or "1 to 18 vs 19 to 36":
#   print ("the program doesn't play that bet")
if bet_type not in good_input:
    bet_type = input ("Enter what type of bet you want: ")

# working on single number bet
elif bet_type == "single number" :
    bet_single_number = input ("enter the number you wish to bet on: ")
    if bet_single_number == red_spaces:
        print ("red has won")
    elif bet_single_number == green_spaces:
        print ("pay 0 or pay 00")
    else:
        print ("black has won")

# working on red vs black bet

elif bet_type == "red vs black":
    bet_color = input ("Enter the color you wish to bet on: " )
    if bet_color == "red" and lucky_num == red_spaces:
        print ("red has won")
    else:
        print ("black has won")

# working on odd vs even
elif bet_type == "odd vs even":
    bet_odd_even = input ("Enter what you want to bet on, odd or even: ")
    if lucky_num % 2 == 1:
        print ("odd won")
    elif lucky_num % 2 == 0:
        print ("even won")
    else:
        print ("pay 0 or pay 00")

# working on 1 to 18 vs 19 to 36
elif bet_type == " 1 to 18 vs 19 to 36":
    bet_num = input("Enter the number you wish to bet")
    if bet_num  in range (1,19):
        print (" 1 to 18 won")
    elif bet_num in range (19,37):
        print ("19 to 36 won")
        

I changed this and

and this

Thank you

1 Like