Your own while/else


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"))
        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"))
            while guesses_left > 0 :
                if guess == random_number:
                    print "you win"
                guesses_left -= 1
                    check_input(raw_input("try again")),
                print "you lose"



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


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