Another is that problem on factorial of a no. using function def f(n): if n==0: r=1 else: r=n*f(n-1) return r print('Ans. is:',r) f(0) what is problem here? Error is showing me that: --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-68-cc9d7ecb020e> in <module>() 6 r=n*f(n-1) 7 return r ----> 8 print('Ans. is:',r) 9 f(0) NameError: name 'r' is not defined
print
def f(n): if n==0: r=1 else: r=n*f(n-1) return r print('Ans. is:',f(5))
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)