 # I don't know how to call my nested function

Hi everyone so I’m doing the python " game of chance " practice project here is the link
and I’m stuck on exercise number 6 ( create a function that simulates some of the rules of roulette).
I created a global function called roulette and inside this function I created two other functions one called “guess_the_number” and the other one called “guess_high_or_low” each one does a different thing than the other my problem is when I want to run either of the local functions I get a “NameError” it says that function name is not defined so my question is how can I do that?.
btw here’s the code ``````def roulette(guess, bet):
def guess_the_number(guess, bet):
if guess == number_guessed:
bet += 35
return "Congratulation you won: " + str(bet) + "\$"
else:
return "Sorry you lost"
return guess_the_number(guess, bet)

def guess_high_or_low(guess, bet):
if guess == "Low":
if number_guessed >= 1 and number_guessed <= 18:
print("It's Low")
bet += bet
return "Congratulation you won: " + str(bet) + "\$"
else:
return "Sorry you lost the number was High!"
else:
if number_guessed >= 19 and number_guessed <=36:
print("It's High")
bet += bet
return "Congratulation you won: " + str(bet) + "\$"
else:
return "Sorry you lost the number was Low!"
return guess_high_or_low(guess, bet)

print(guess_high_or_low("High", 50))
``````

Hello, @khloecalderon7050276, and welcome to the forums!

The nested functions are only available inside the parent function. You may want to consider making `roulette` a `class` instead. Then you still have a few errors to work through including re-working the game logic to accurately access winning/losing. If classes are not familiar to you yet, you’ll have to refactor your code to call your nested functions from within the `roulette` function.

Edit: Actually, your game logic works fine for determining winning/losing once the other issues are addressed.

``````print(guess_high_or_low("High", 50))
``````

You’ll need to do

``````print(roulette("High", 50)) #play guess_high_or_low
#or
print(roulette(27, 50)) #play guess_the_number
``````

Then inside the `roulette` function, rather than having these two lines immediately follow their respective function definitions, you’ll need a way to determine which of them to execute.

``````return guess_the_number(guess, bet)
#and
return guess_high_or_low(guess, bet)
``````

Hint: Possibly something like this:

``````  if type(guess) == int:
return guess_the_number(guess, bet)
else:
return guess_high_or_low(guess, bet)
``````

Also need to make sure that `number_guessed` gets defined at the beginning of the function. I’d consider renaming it since it is the result of spinning the wheel.