Your own while / else (python)


#1

I would like to see if anyone can find the issue within my code.
The error says:
File “python”, line 14
else:
Syntax error: invalid syntax


# 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."```

#2
guesses_left -= 1

This line of code should be inside of while loop.remember not inside of if.


#3

Thank you :slight_smile: slight_smile:


#4

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