Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions