I am trying to make a Roulette game with a command-prompt interface. Roulette is about betting, and therefor a large part of the game is about the money you lose and win. I am trying to make a variable to tell the player how much money I have before I make another bet. I am not yet finished with the game and therefor only have 3 options available, but I wanted to fix this bug before I continued. I keep getting the error "UnboundLocalError: local variable 'money' referenced before assignment" Here is the code: from random import randint from time import sleep from os import system
def how_much():
print("How much money do you want to place on this bet?")
global amount
amount = int(input())
def game():
def bet():
bet = input("What type of bet do you want to make?\n")
how_much()
#Start Bet type 1
if bet == "1":
roll = randint(1,36)
if roll <= 3:
print("You bet correcty!")
money = money + amount
game()
else:
print("You lose!")
money = money - amount
game()
#Start bet type 2
elif bet == "2":
roll = randint(1, 36)
if roll <= 4:
print("You bet correcty!")
money = money + amount
game()
else:
print("You lose!")
money = money - amount
game()
#Start bet type 3
elif bet == "3":
roll = randint(1, 36)
else:
print("Invalid argument.")
bet()
global money
money = int(1000)
print("Welcome to Roulette")
print("Your Wallet has", money, "Euros in it.")
print("1. First 3 Numbers\n2. First 4 Numbers\n3. One Number\n4. Upper-half or Lower-half\n5. Dozens\n6. Odd or Even\n7. Column\n8. Line\n9. 2 Lines\n10. Red or Black\n11. 2 Neighbors\n12. 4 Neighbors\n0. Exit")
bet()
game()