183k views
4 votes
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

1 Answer

4 votes

Answer:

Following are code of factorial in python language

def factorial(n): # function

result=1 #variable

for x in range(2,n+1): #iterating the loop

result=result*x #storing result

return result #return result

for n in range(10): #iterating loop

print(n,factorial(n)) #print factorial

Output:

Following are the attachment of output

Step-by-step explanation:

Missing information :

In the question the information is missing the code is missing which we have to correct it following are the code that are mention below.

def factorial(n): # function

result=1 #variable

for x in range( ): #iterating the loop

result= #storing result

return #return result

for n in range( ): #iterating loop

print(n,factorial(n)) #print factorial

Following are the description of code

  • We have create a function factorial in this we have pass the one parameter i.e "n".
  • In the for loop we have pass 2,n+1 which has been used to iterating the loop calculating factorial and string the result in the result variable
  • In the main function we have pass the range on which we have to calculated the factorial
  • Finally the print function will print the factorial .

Following are the attachment snip of code in the python language

Fill in the blanks to make the factorial function return the factorial of n. Then-example-1
Fill in the blanks to make the factorial function return the factorial of n. Then-example-2
User Esaruoho
by
6.9k points