Your own while / else


I had written my code according to instructions, i have written else statement correct. could any one help me where my code went wrong?


03. If they guess correctly, print 'You win!' and break

It starts with if meaning you need an if statement (also you need one before you can use else properly). Instruction 03. tells you to create an if statement in which if the guess is equal to the random number you generate, print "You Win!".

Also everything starting from guesses_left -= 1 to print 'You lose!'(inclusive) must be in the loop so you need to indent them into the loop (they are currently outside the loop and may cause an infinite loop).


hi could u forward me this code. so i can have an idea.


You just need to add an if statement before your print 'You win!' which should check if the user's input guess is equal (==) to your random_number (which is what instruction 03. is saying. And indent everything properly.


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