Question

4- Write a program by using function that asks the user for entering a positive integer...

4- Write a program by using function that asks the user for entering a positive integer
number (a) and then calculate the factorial of the number. Draw the Trace Table
(8 Marks)( k/2, T/2, C/2, A/2)
Enter a number: 4
Factorial (4) = 4! =4*3*2*1=24

use python pls

0 0
Add a comment Improve this question Transcribed image text
Answer #1

BECAUSE OF THE IDENTATION PROBLEM WHILE SUBMITTING THE CODE SO THAT IM ALSO GIVING YOU THE SCREENSHOT SO THAT YOU CAN REFER IT :

main.py 1 def factorial(n): # factorial function 2 if n == 1 : # if n is 1 return n 4 else: 5 return n * (n - 1) # recursfive

PYTHON CODE :

def factorial(n): # factorial function
if n == 1 : # if n is 1
return n
else:
return n * (n - 1) # recursive function

n = int(input("Enter the number: ")) # read the number
if n == 0 : # if n is zero
print("Factorial of 0 is : 1")
else:
print("Factorial of",n,"is :",factorial(n)) # print the result

INPUT & OUTPUT :

Enter the number: 4 Factorial of 4 is : 12 ... Program finished with exit code 0 Press ENTER to exit console.

* fact. (n-1) ។ food (3) /l 3 tact (2) / IN 2 fact (1) 4*3*2*1 24

Add a comment
Know the answer?
Add Answer to:
4- Write a program by using function that asks the user for entering a positive integer...
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
ADVERTISEMENT