0

For my first project I'm making a number game, the computer guesses a number and the user tells the computer if The guess is greater than, less than, or equal to the number they are thinking. My code is set up like this:

guessNumber = 0

def greaterThan():

    guessNumber += 1
    print("Is your number less than, greater than, or equal to ", (100 + (100 / 2 ** guessNumber)))

''' I know my math is wrong here but I'm trying to get the program to work first '''

    lessORgreater = input()

''' I have a function for lessThan() and equalTo() '''

lessORgreater.lower()

 #pretty sure this needs to be fixed because I don't think it's right

If (lessORgreater == "greater"):

    greaterThan()

That's basically what I have. It's very similar for the lessThan() and equalTo() just tells the user the computer won.

The error I'm getting says that

Local variable 'guess number' referenced before assigned

Yu Hao
  • 119,891
  • 44
  • 235
  • 294

1 Answers1

0

Use

def greaterThan():
    global guessNumber
    guessNumber += 1
    ...

You can look here to learn more about global.

Ren
  • 2,852
  • 2
  • 23
  • 45