Question: Python : rewrite the factorial function so that everytime it calls itself it adds an indentation ( see examples ) #here is our original definition

Python :
rewrite the factorial function so that everytime it calls itself it adds an indentation (see examples)
#here is our original definition
def factorial( n ):
if n <=1:
return 1
return n * factorial( n-1)
In the example (below) it is easy to see all the recursive calls to the factorial function.
your file must be called fact.py.
in that file you must define a function called factorial
end the file with the following line (so that it asks for input)
for this to work your function must print something everytime it is called, and it must print something everytime it returns a value. factorial(int(input("enter an integer: ")))
Examples
% python3 fact.py
enter an integer: 5
factorial(5)
factorial(4)
factorial(3)
factorial(2)
factorial(1)
returns 1
returns 2*1=2
returns 3*2=6
returns 4*6=24
returns 5*24=120
%

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!