1

I'm new to Python and Stack Overflow so please bear with me. I'm creating a 'guess the number' game. When the program offers the user a hint the user should either enter 'y' or 'n' as indicated: hint_option = str(input('Incorrect! Do you want a hint? (Y/N): ')).lower() otherwise, if another letter (e.g.) is entered I want the program to print Invalid input! Please try again

hint_loop = False
while hint_loop != True:
    if hint_option == 'y':
        if user_guess > random_num:
            hint = 'too high'
        else:
            hint = 'too low'
        print(f'''Hint: Your guess was {hint}
        ''')
        total_hints += 1
        break
    elif hint_option == 'n':
        break
    else:
        print('Invalid input! Please try again')

I don't know what to do, could someone please help me?

quamrana
  • 37,849
  • 12
  • 53
  • 71
gh.06_
  • 21
  • 1
  • 2
    Could you please edit your comment to include what is currently going wrong? – Tom Aarsen Jan 22 '22 at 10:57
  • Why do you need a `while` loop for giving the hint? An `if...else` statement is enough. And what _is_ the error? The only thing I can see is an infinite loop when the `else` block is triggered. You can rectify it using a `break` statement. – NameError Jan 22 '22 at 11:04
  • 1
    Please provide a [mcve] rather than just a fragment which contains references to variables which are defined elsewhere. – John Coleman Jan 22 '22 at 11:07

0 Answers0