python recursion is not working as expected -


i'm new coding , trying teach myself recursion building simple function calls itself. code behaving differently how expecting:

get user input number must not greater 50

def getinput():   input = int(raw_input("type number under 50 >>> "))   if input < 50:     return input   else:     print input, "no, must under 50"     getinput()  print getinput() 

this results in following behavior:

this bit expected

c:\python27>python recur.py

type number under 50 >>> 23

23

this bit unexpected

c:\python27>python recur.py

type number under 50 >>> 63

63 no, must under 50

type number under 50 >>> 23

none

my question is, why last line "none", , not 23? code seems correctly call function again if user inputs number 50 or greater, why doesn't second call return 23 (the same initial output)?

any advice appreciated

you don't return result of getinput() if number greater 50

def getinput(): input = int(raw_input("type number under 50 >>> "))   if input < 50:     return input   else:     print input, "no, must under 50"     return getinput()   print getinput()   

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -