This community-built FAQ covers the “Your own while / else” exercise in Codecademy’s lessons on Python.
FAQs for the Codecademy Python exercise exercisename:
Have a new question or can answer someone else’s? Reply () to an existing thread!
Agree with a comment or answer? Like () to up-vote the contribution!
Need broader help or resources about Python in general? Go here!
Want to take the conversation in a totally different direction? Join our wider discussions.
Learn more about how to use this guide.
Found a bug? Report it!
Have a question about your account, billing, Pro, or Pro Intensive? Reach out to our support team!
None of the above? Find out where to ask other questions here!
Other FAQs
The following are links to additional questions that our community has asked about this exercise:
- This list will contain other frequently asked questions that aren’t quite as popular as the ones above.
- Currently there have not been enough questions asked and answered about this exercise to populate this FAQ section.
- This FAQ is built and maintained by you, the Codecademy community – help yourself and other learners like you by contributing!
Not seeing your question? It may still have been asked before – try () in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post ().
Alot of the time when fill the raw input, the text gets spammed and uses all of the guesses
1 Like
from random import randint
# Generates a number from 1 through 10 inclusive
random_number = randint(1, 10)
guesses_left = 3
# Start your game!
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."
when I couldn’t fix the code myself, I even referenced the given solution. But for some reason I’m still getting an error message—
Your guess: 4
Traceback (most recent call last):
File “python”, line 10, in
ExecTimeoutException: Program took too long to terminate.
So I get one chance to enter my guess and then you can see what happens. This is a bug, right?
1 Like
I’m getting a similar problem. I used the given solution and still got -
Traceback (most recent call last):
File “python”, line 9, in
ValueError: invalid literal for int() with base 10: ‘’
It’s not the first exercise I’ve got an error message on with code identical to the solution, I’ve also seen the same one you got.
When I tried this code, i refreshed the page after I got this error. It’s a bug and you can refresh your page for the program to work.
1 Like
Somehow this problem still exists and I found that writing “guesses_left = guesses_left -1” fixed it despite doing exactly the same thing
I have the same issue even when I run the solution. However, when I refreshed the page it started working properly.
from random import randint
Generates a number from 1 through 10 inclusive
random_number = randint(1, 10)
guesses_left = 3
Start your game!
while guesses_left > 0:
guess = int(raw_input(“Your guess:”))
if guess == random_number:
print “You win!”
break
guesses_left = guesses_left -1
else:
print “You lose!”
Your guess:Traceback (most recent call last):
File “python”, line 9, in
ExecTimeoutException: Program took too long to terminate.
“I just does not make any sense!”
My codes are:
from random import randint
Generates a number from 1 through 10 inclusive
random_number = randint(1, 10)
guesses_left = 3
Start your game!
while guesses_left > 0:
guess = int(raw_input("Your guess: "))
if guess == random_number:
print “You win!”
break
else:
guesses_left -= 1
print “You lose.”
The solution is:
from random import randint
Generates a number from 1 through 10 inclusive
random_number = randint(1, 10)
guesses_left = 3
Start your game!
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.”