Your own while/else


#1


https://www.codecademy.com/en/courses/python-beginner-en-cxMGf/0/8?curriculum_id=4f89dab3d788890003000096

I can not figure out a way to decrement my variable guesses_left

It Should subtract the amount of attempts/guesses left after every iteration


from random import randint

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

# Start your game!
check = raw_input("guess a number 1-10")

def check_input(test):
    #checks if input is a number
    if test.isalpha():
        check_input(raw_input("that is not a number"))
    else: 
        guess = int(test) #changes input into an integer
        if guess > 10 or guess < 0 : #checks range of input
            check_input(raw_input("out of range"))
        else:
            while guesses_left > 0 :
                if guess == random_number:
                    print "you win"
                    break
                guesses_left -= 1
                else: 
                    check_input(raw_input("try again")),
                    
            else: 
                print "you lose"
    
check_input(check)


#2


#3

Try setting this variable before the loop, but inside the function.


#4

A post was split to a new topic: No idea why it shows me that I don't close the loop


#6