Oct-21-2017, 02:22 AM
(This post was last modified: Oct-21-2017, 02:23 AM by chadandersen1.)
The program now works as expected, and checks if the bet color is invalid, as well as checks if the bet amount is a negative number or more than the players balance. Thank you to both of you for your help, I learned quite a bit and without you I wouldn't have gotten the program to work.
import random red = [1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36] black = [2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35] validcolors = [1, 2, 3, 4] balance=5000 print("Welcome to Chad's Online Roulette game!") print("Your starting balance is $50, or 5000 tokens.") while True: betcolor = int(input("Bet on red (enter 1), black (enter 2), or green (enter 3). Enter 4 to stop playing. ")) if betcolor == 4: print("Your ending balance is {} tokens.".format(balance)) while True: if betcolor not in validcolors: print("{} is not a valid color. Please enter a valid color.".format(betcolor)) betcolor = int(input("Bet on red (enter 1), black (enter 2), or green (enter 3). Enter 4 to stop playing. ")) if betcolor in validcolors: break betamount = int(input("How many tokens would you like to bet?")) while True: if betamount > balance or betamount < 0: print("Your bet amount is invalid.") betamount = int(input("How many tokens would you like to bet?")) if betamount < balance or betamount == balance: break roll = random.randint(-1,36) greenwin = betamount*35 redblackwin = betamount*2 balance -= betamount if betcolor == 1 and roll in red: balance += redblackwin elif betcolor == 2 and roll in black: balance += redblackwin elif betcolor == 3 and roll in (0, -1): balance += greenwin print("The roll was a {}.".format(roll)) print("Your balance is now {} tokens.".format(balance)) if balance == 0: print("You have ran out of money. Better luck next time!") break