[Tutor] Function returns 'None'
Luke Paireepinart
rabidpoobear at gmail.com
Sun Jul 11 17:50:06 CEST 2010
I think the new version is harder to understand.
Sent from my iPhone
On Jul 11, 2010, at 10:43 AM, Nick Raptis <airscorp at otenet.gr> wrote:
> On 07/11/2010 06:28 PM, Nick Raptis wrote:
>>
>> def recursfac(x,carryover=1):
>> print 'x:',x,'carryover:', carryover
>> if x > 1:
>> carryover *= x
>> carryover = recursfac(x-1, carryover)
>> return carryover
>>
>> And this returns
>> x: 3 carryover: 1
>> x: 2 carryover: 3
>> x: 1 carryover: 6
>> 6
>>
>> Done!
>>
>
> Also, I realized that my final code may be tough to decipher now.. A nicer way to write it would be (the functionality is still exactly the same):
>
> def recursfac(x,carryover=1):
> print 'x:',x,'carryover:', carryover
> if x > 1:
> carryover *= x
> result = recursfac(x-1, carryover)
> else:
> # done with recursion, start our way up
> result = carryover
> return result
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list