Using python Problem 7 (10 points). Given a number n calculate n! using a while
ID: 3857149 • Letter: U
Question
Using pythonProblem 7 (10 points). Given a number n calculate n! using a while loop. n!, called n factorial, is defined as the product of numbers 1 through n. For example 4! = 1 X 2 X 3 X 4 = 24 For example 2! = 1 X 2 = 2 For example 5! = 1 X 2 X 3 X 4 X 5 = 120 Sample program output: Please enter n: 3 3 factorial is 6
Using python
Problem 7 (10 points). Given a number n calculate n! using a while loop. n!, called n factorial, is defined as the product of numbers 1 through n. For example 4! = 1 X 2 X 3 X 4 = 24 For example 2! = 1 X 2 = 2 For example 5! = 1 X 2 X 3 X 4 X 5 = 120 Sample program output: Please enter n: 3 3 factorial is 6
Problem 7 (10 points). Given a number n calculate n! using a while loop. n!, called n factorial, is defined as the product of numbers 1 through n. For example 4! = 1 X 2 X 3 X 4 = 24 For example 2! = 1 X 2 = 2 For example 5! = 1 X 2 X 3 X 4 X 5 = 120 Sample program output: Please enter n: 3 3 factorial is 6 Problem 7 (10 points). Given a number n calculate n! using a while loop. n!, called n factorial, is defined as the product of numbers 1 through n. For example 4! = 1 X 2 X 3 X 4 = 24 For example 2! = 1 X 2 = 2 For example 5! = 1 X 2 X 3 X 4 X 5 = 120 Sample program output: Please enter n: 3 3 factorial is 6
Explanation / Answer
Answer:
def factorial():
n = input ('Please enter n:')
input=1
i=1
while (i<=n):
input=input*i
i=i+1
print(' %d factorial is %d' %(n,input))
Output:
Please enter n: 5
5 factorial is 120
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.