Debugging and Syntax Problems : (

print("Please think of a secret number between 0 and 100!")
low = 0
high = 100

while True:
    num_guess = (high+low)/2
    print("Is this your secret number" +str(num_guess) + "?")
    user_inp = input(" Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly."
    if user_inp == 'h':
        high = num_guess
    elif user_inp == 'l':
        low = num_guess
    elif user_inp == 'c':
        break
    else:
        print('Sorry, I did not understand your input')
    

print('Game Over. Your secret number was' + num_guess)
1 Like

If you require help you should:

  1. describe what is the problem;
  2. describe what you already tried to do in order to solve it;
  3. format the code in your post.

The last point is super important especially if we talk about Python where indentation matters. I edited your post, you can open it in edit view and check how to format the code (backticks).


Back to your problem. Currently execution of your code results in SyntaxError: invalid syntax error pointing at line:

if user_inp == 'h':

this usually means that something is wrong with your previous line:

user_inp = input(" Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly."

Check the indentation, parentheses and quotation marks :slight_smile:

2 Likes

I have spotted two errors:

  1. You’re missing a closing parentheses on your input.
user_inp = input(" Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.")
  1. Your program is breaking after you jump of your loop, because you are trying to concatenate your “Game Over” string with a float. This will result in an error. You must parse your num_guess variable as a string if you want to concatenate it.
print('Game Over. Your secret number was ' + str(num_guess))

Good luck!