Error in following code

Jay Loden python at jayloden.com
Fri Jun 22 02:12:00 EDT 2007


zaperaj at gmail.com wrote:
> [root at localhost root]# python t4.py
> enter number: 6
> [root at localhost root]#
> 
> i.e it takes the input but doesn't print anything. If anybody can
> help... Thanx!

You're creating a function called "f" in the first line, but the script never does anything with it, so it never gets executed. You need to actually call your function after creating it: 

-----

#! usr/bin/env/python

def f(n=int(raw_input("enter number: "))):
     print 'n=',n
     if n>1:
             return n*f(n-1)
     else:
             print 'end'
	     return 1

f()

-----

That should do the trick.





More information about the Python-list mailing list