Question 2 Fill in the blanks to make the factorial function return the factorial of n. Then, print the first 10 factorials (from 0 to 9) with the corresponding number. Remember that the factorial of a number is defined as the product of an integer and all integers before it. For example, the factorial of five (5!) is equal to 1*2*3*4*5=120. Also recall that the factorial of zero (0!) is equal to 1. def factorial(n): result = 1 for x in range(1,9): result = ___ * ___ return ___ for n in range(___,___): print(n, factorial(n+___))
Answers
Answered by
11
Answer:
ef factorial(n):
result = 1
if n == 0:
result = 1
for x in range(1,n):
result = result*x
return result
for n in range(0,10):
print(n, factorial(n+1))
Explanation:
Answered by
0
result = 1 for x in range (1,9):result=result*x return result for n in range (0,10): print(n, factorial(n+1))
Explanation:
- For printing the first ten factorials from 0 to 9 from the number whose factorial we will first print.
- We are taking range (1,9) since the factorials of all the 10 numbers, starting from 0 and ending at number 9 will have to be printed. Hence the loop has to execute 10 times in order to print factorials of all the ten numbers.
- For n in range (0,10), we are considering this because a factorial is calculated in this manner, as mentioned in the description. Lastly, we are printing the number as well as the factorials of all the consecutive numbers.
Hence, the answer will be result = 1 for x in range (1,9):result=result*x return result for n in range (0,10): print(n, factorial(n+1)).
Learn more about factorial programs
https://brainly.in/question/11962694?msp_srt_exp=5
Learn more here
https://brainly.in/question/35874050?msp_srt_exp=5
Similar questions