Your own while / else


Stuck on

My code continues to give me the error:
Traceback (most recent call last):
File "python", line 9, in
ValueError: invalid literal for int() with base 10: ''

I don't have a clue what is causing this error, and would really appreciate any help :slight_smile:

from random import randint

random_number = randint(1, 10)

guesses_left = 3
while guesses_left > 0:
    guess = int(raw_input("Your guess: "))
    if guess == random_number:
        print "You win!"
    guesses_left -= 1
    print "You lose."

Thank you in advance!!!


Your error message looks incomplete, it ends in an opening quote but has no closing quote (take care that information provided is intact/complete)

If it says an empty string, then consider what it says. You can indeed not convert an empty string to a number, it's a nonsensical operation which is why python won't do it and instead telling you that you're being silly (raising an exception)


Think I get it now. Thank you!


still dont get what is the problem according to your answer, can you explain again?


Got nothing else to explain. You'd need to be more specific


Where can you see an empty str?


Their error message says that's what happened.


The code works just fine...


I know. I just messed up the input I gave it, but the code is actually correct :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.