8. Your own while / else - Code is correct but it exercise doesn't let me pass


#1

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/loops/exercises/your-own-while--else?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>
“Did you include an else for the while loop?”

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
    if guesses_left == 0:
      print "You lose"
      print random_number

#2

Perhaps your code has the overall correct behaviour (I’m not going to look), but it does miss the point of the exercise, and that’s what the message you’re getting is about.


#3

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