how to think like a computer scientist

john boy xray_alpha_charlie at yahoo.com
Fri Nov 11 23:25:19 EST 2005


Question for the following program: sec 5.5
 
def factorial (n):
   if n == 0:
      return 1
   else:
      recurse = factorial (n-1)
      result = n * recurse
      return result
 
How come whenever I state the function with "n" given a value it prints no results in the interpreter for EX:
 
def factorial (n):
   if n == 0:
      return 1
   else:
      recurse = factorial (n-1)
      result = n * recurse
      return result
factorial (3)
 
So instead I have to give a "print" command to make the result appear in the interpreter 
for EX:

 
def factorial (n):
   if n == 0:
      return 1
   else:
      recurse = factorial (n-1)
      result = n * recurse
      return result
print factorial(3)
 
Is this correct....should I have to give a print command??


		
---------------------------------
 Yahoo! FareChase - Search multiple travel sites in one click.  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051111/7e2ae29d/attachment.html>


More information about the Python-list mailing list