Your own while / else: Code running fine but Exercise not moving forward!


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:
    g=int(raw_input("Your guess: "))
    if g==random_number:
        print "You Win!"
        print "You Lose"


What have I done wrong here? Tried multiple times where win and loss both have been executed outcomes! Still can't make the move and showing "Oops, try again.
Did you include an else for the while loop?"
I have included the while loop. What should be done next? Any help will be highly appreciated :slight_smile:


the else should be at the same intend level as the while loop, so else runs after the loop is finished. the guesses_left reduction should be inside the while loop


Did that and it run but what was wrong with my code? It also executed properly! :frowning:


can i see an updated version of your code?


It was like what I have posted sir.


then the indent(ion) level of else is not correct?


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