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


#1





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!"
        break
    
    
    else:
        print "You Lose"
        

    guesses_left-=1

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:


#2

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


#3

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


#4

can i see an updated version of your code?


#5

It was like what I have posted sir.


#6

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


#10

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