[Tutor] Problem with python

Matthew Nunes matthewnunes at hotmail.com
Tue Oct 19 23:02:43 CEST 2010

To whom it may concern, 
                                   Hi, I've just started learning how to program in python using Allan B. Downy's book "How to think like a computer scientist" and it explained something in the recursion chapter which have still been unable to understand. It wrote a piece of code for the factorial function in math for example 3! is 3 * 2 * 1. I cannot understand the how it claimed the code executed, and  logically it makes no sense to me. Please explain it to me, as I have spent hours trying to get my head around it, as the book(in my opinion) did not explain it well. Here it is: 
def factorial(n):
if n == 0:
return 1
recurse = factorial(n-1)
result = n * recurse
return result
If there is and easier piece of code that you know of that can be used for factorial, if you could please also tell me that.
Thank you for your time.  		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101020/00b0285d/attachment.html>

More information about the Tutor mailing list