Your own while/else


#1

Why does it keep saying that else: syntax is wrong?
It seems fine but I'm stuck.
Any suggestions?


#2

else should be after if or while, its currently after you update a variable


#3

Thanks for answering
Yeah I tried placing the variable'guesses_left' after the else condition and it's showing error
The variable was placed after the else condition.
Here's the result after execution


#4

why place it after else? The user loses after they are out of guesses (which is after the loop is finished running)


#5

I know, But if Iam placing it after if and above else. It's showing error. The first image


This one.


#6

but you want to get while/else, since you want else to run when the user runs out of gueses


#7

Hey thanks for answering. it solved my problem.All along I was trying for if/else.My bad


#8

while guesses_left > 0:
...
if guess == random_number:
...
break
else:
...


#9

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