Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialArikaturika Tumojenko
8,897 PointsValuerError: invalid literal for int() with base 10: '' meaning?
So, this is my code:
# generate a random number between 1 and 10
secret_num = random.randint(1, 10)
while True:
# get a number guess form the player
guess = int(input("Guess a number between 1 and 10: "))
# compare guess to secret number
if guess == secret_num:
print("Your guess is correct! My number was {}".format(secret_num))
break
else:
print("Ups, your guess is incorrect! Try again!")
continue
The only difference between what Kenneth wrote and what I wrote is that I added "continue" in the else statement. I repeatedly entered number 5 in order to guess the name and after a few times I got this error:
"ValuerError: invalid literal for int() with base 10:"
The program stopped working afterwards. Does anyone know what does it mean and why I got this error?
2 Answers
William Harrison
9,585 PointsA non-integer was entered. When I ran your code it ran fine, but when I hit enter without a number first. ValueError: invalid literal for int() with base 10: '' At the end of my error is an empty string, when I enter + I got : ValueError: invalid literal for int() with base 10: '+'. I hope this helps find what happened.
Steven Parker
231,275 PointsMy guess is that while you "repeatedly entered number 5", you accidentally entered another non-numeric character instead or along with it. That would cause that specific error and stop the program.
The "continue" at the end is not needed, but doesn't cause any issues.