8. Your own While/Else


from random import randint

# Generates a number from 1 through 10 inclusive
random_number = randint(1, 10)

guesses_left = 3
# Start your game!

I'm unable to do this code....pls help me to sort it out.


Here is what I did. Basically what random_number = randint(1, 10) does is sets a randomly generated number that remains static until called upon again. So that part is already set. You need to write a while code that checks that 'guesses_left' is above 0, as long as it's above zero, it will take a raw input and see if that number is equal to the already generated random_number. Otherwise the code will just repeat and guesses_left will decrease by one. Does this make sense?

while guesses_left > 0:
    guess = int(raw_input('Your guess: '))
    if guess == random_number:
        print 'You win!'
    guesses_left -= 1
    print 'You lose..'