Wes Wes - 7 months ago 13
Python Question

Number Guessing program. Too high too low issue

I'm a very new programmer and I suck. I was trying to make a number guessing game, but I had a problem with the "Too high, Too low part." My IDE (PyCharm) kept saying

syntax error traceback line 18
. I kept tweaking that line but I'm beat. Here's the code.

Thanks in advance.

import random

print("Guess a number between 1 and 100. ")

randomNum = random.randint(1, 100)
found = False

while not found:
print("Remember, you can only guess between the numbers 1-100!")

userEst = int(input("Guess here:"))
if userEst == randomNum:
print("You guessed right!!!")
found=True

if userEst > randomNum:
print("Too high!")

if userEst < randomNum:
print("Too low!")

Answer

Looks like you have one of those annoying indentation errors. Python gets picky about that.

if userEst == randomNum:
        print("You guessed right!!!")
        found=True

should be

if userEst == randomNum:
    print("You guessed right!!!")
    found=True