Python Forum
Trouble with simple roulette game
Thread Rating:
  • 2 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble with simple roulette game
#10
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
Reply


Messages In This Thread
RE: Trouble with simple roulette game - by Mekire - Oct-19-2017, 08:10 AM
RE: Trouble with simple roulette game - by Mekire - Oct-20-2017, 12:15 AM
RE: Trouble with simple roulette game - by Mekire - Oct-20-2017, 11:49 PM
RE: Trouble with simple roulette game - by chadandersen1 - Oct-21-2017, 02:22 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple cards game blackpanda 3 4,318 Apr-10-2020, 08:46 PM
Last Post: TomToad
  Need help with simple guessing game! ghost0fkarma 2 2,865 Nov-03-2018, 01:19 AM
Last Post: ghost0fkarma
  Easy equipment system for simple game and problems with it naisyrk 3 3,362 Sep-01-2018, 10:05 AM
Last Post: Gribouillis
  Errors in simple text adventure game? ecloev 5 5,003 Apr-10-2018, 05:55 PM
Last Post: nilamo
  Simple Hangman Game Issue andrew95 2 4,395 Apr-02-2018, 02:24 PM
Last Post: andrew95

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020