python - Can anyone tell me what's wrong with my function? -
i'm working on project , keep getting problem when code tries return "guess" variable, instead of returning value of "guess" goes line 9 converts value string reason, , returns that. when go use returned value in something, python says value "nonetype".
def ask_question(max_length, roworcol, guessnumber): guess = raw_input("what "+roworcol+" number of "+guessnumber+" guess? ") try: guess = int(guess) if guess <= max_length: return guess else: print "that number big, must no larger " +str(max_length) ask_question(max_length, roworcol, guessnumber) except(typeerror): print "only numbers accepted, please try again!" ask_question(max_length, roworcol, guessnumber)
i call function line:
first_guess_row = ask_question(4, "row", "first")
is there i'm missing?
of course branches need return....
... else: print "that number big, must no larger " +str(max_length) return ask_question(max_length, roworcol, guessnumber) except(typeerror): print "only numbers accepted, please try again!" return ask_question(max_length, roworcol, guessnumber)
before recalling function ... throwing away return value