Your own while / else


#1



Stuck on https://www.codecademy.com/courses/python-beginner-en-cxMGf/0/8?curriculum_id=4f89dab3d788890003000096#


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!"
        break
    guesses_left -= 1
else:
    print "You lose."


Thank you in advance!!!


#2

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)


#3

Think I get it now. Thank you!


#4

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


#5

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


#6

Where can you see an empty str?


#7

Their error message says that's what happened.


#8

The code works just fine...


#9

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


#10

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