[Tutor] Function returns 'None'
Alan Gauld
alan.gauld at btinternet.com
Sun Jul 11 17:09:02 CEST 2010
"Dominik Danter" <dotti at socialnerds.org> wrote
> def recursfac(x,carryover=1):
> print 'x:',x,'carryover:', carryover
> if x > 1:
> carryover *= x
> recursfac(x-1, carryover)
No return value here so when the reursed function returns carryover
we have nowhere to go in the calling function so we return None.
> else:
> return carryover
This returns a value to the calling function, but in
the recursive case that returned vaklue uis thrown away
as the comment above shows.
you need to add a return statement where you call recursively.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list