Ask coding questions

← Back to all posts
Why do I get this error?
JordanDixon1

python
import time, os, random
#Functions for Betting Arena.

level_counter = 2.5

lvlbar = 0

lvlneed = 2

upgrades = []

level = 1

money = 57

job = 'McDonald\'s Employee'

daily_earnings = 9

def bet():
print('The horse races are about to begin! Pick your horse and the amount you would like to bet.')
print('Horses are as follows:')
print('1)The Speedy Lightning')
print('2)Hitmarker')
print('3)The Trashy Terror')
print('4)The Slippery Shadow.')
horse = input('Which horse are you gonna bet on: ')
if horse == '1':
print('You bet on The Speedy Lightning!')
elif horse == '2':
print('You bet on the Hitmarker!')
elif horse == '3':
print('You bet on... The Trashy Terror..?')
elif horse == '4':
print('You bet on The Slippery Shadow!')

def joob():
if job == 'McDonald\'s Employee':
print('Flip the burgers!')
print('1)Flip \n2)Help')
user = input('Choice: ')

I keep on getting local variable defined in enclosing scope.

Answered by PizzaRules668 [earned 5 cycles]
View Answer
Voters
PizzaRules668
Deacon_Cronin
JordanDixon1
Comments
hotnewtop
PizzaRules668

Right after you define joob() put global money

JordanDixon1

@PizzaRules668 You fixed my problem, however another one arose. When the game stops the tutorial. (Starts up game()) I can't make any selection.

PizzaRules668

@JordanDixon1 Your input is a str, in python you can not compare a str and a int. you can make user a int by doing
user = int(user)
or
user = int(input('Your choice: ')

JordanDixon1

@PizzaRules668 Ok, I have fixed most problems. However, now I have a new problem... The variable money when printed in the stat() isn't printing the real number however, in bet() it does. (To be honest, I think I want to invite you that way we can work on it together.)

PizzaRules668

@JordanDixon1 It is not a global variable.
fix: global money, level, job, daily_earnings
you can copy and paste after line 28

JordanDixon1

@PizzaRules668 It didn't work...

PizzaRules668
JordanDixon1

@PizzaRules668 Ok, I fixed it. It was because I set the variable twice once in the def and once in the functions

PizzaRules668
JordanDixon1

@PizzaRules668 Nevermind, I didn't fix a darn thing.