python - Recursive Py Program Returning j=none when j==1? -


recursive py program returning j=none when j==1? not make sense base case specified j must equal 1 , not call function again.

import sys y=10 def decrease(j):     if j==1:         print('j =' + str(j) + '(1)')         print('returning j')         return j     else:         print('j =' + str(j) + '(not 1)')         print('decreasing j')         j = j-1         print('calling decrease j')         decrease(j) y=decrease(y) print('complete') print(y) 

you forget return decrease(j) @ end of second branch.

usually when encounter unexpected none returned function, check first branches end return statement. without it, function returns none


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -