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!")
Be aware that in in python, the indentation is very significant. Each code block has its indentation read more at: link . Thus, you need to change your code to:
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 = input("Guess here:")
if userEst == randomNum:
print("You guessed right!!!")
found=True
if userEst > randomNum:
print("Too high!")
if userEst < randomNum:
print("Too low!")
By the way, you do not suck.
Good Luck.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.