Question
Please do it in python
Question 34 Write a recursive function fac2(n) to compute the factorial of n. n!-1 23 .. (n-1) t n ni # n * (n-1) * 3 * 2 * 1 orn
0 0
Add a comment Improve this question Transcribed image text
Answer #1

def fac2(n): # function defination start
if n == 1: # last execution for value n =1. program #executes for n, n-1. n-2 and so on
return n
else:
return n*fac2(n-1)

Factnum = int(input("Enter Number of which factorial is required ")) # Accept #number whose factorial is required, convert to integer else error with phthon 3 else we simply use input excluding int for prev version
if Factnum == 0: # for value 0, #factorial is 1 so we can straight end program here
print("Factorial is 1")
else:
print("Factorial of " ,fac2(Factnum)) #call recursive #function

RESTART: C:\Users\Emmanuel\AppDatalLocal\Programs\Python\Python36-321main.py Enter Number of which factorial is required Fact

Add a comment
Know the answer?
Add Answer to:
Please do it in python Question 34 Write a recursive function fac2(n) to compute the factorial...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT