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


<Below this line, add a link to the EXACT exercise that you are stuck at.>

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


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.


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