mercredi 22 avril 2015

Can anyone tell me what's wrong with my function?

I'm working on this project and I keep getting this problem when the code tries to return the "guess" variable, instead of returning the value of "guess" it goes to line 9 which converts the value into a string for some reason, and then returns that. when I go to use the returned value in something, Python says that the value is "NoneType".

def ask_question(max_length, rowOrCol, guessNumber):
    guess = raw_input("What is the "+rowOrCol+" number of your "+guessNumber+" guess? ")
    try:
        guess = int(guess)
        if guess <= max_length:
            return guess
        else:
            print "That number was too big, it must be no larger then " +str(max_length)
            ask_question(max_length, rowOrCol, guessNumber)
    except(TypeError):
        print "Only numbers are accepted, please try again!"
        ask_question(max_length, rowOrCol, guessNumber)

I call the function with this line:

first_guess_row = ask_question(4, "row", "first")

Is there anything that I'm missing?

Aucun commentaire:

Enregistrer un commentaire