In mathematics, the notation n! represents the factorial of the nonnegative integer n. The factorial of n is the product of all the nonnegative integers from 1 to n. For example: 7! = 1 x 2 x 3 x 4 x 5 x 6 x 7 = 5,040 Write a program that lets the user enter a nonnegative integer and then uses a loop to calculate the factorial of that number. Print the factorial to standard output.

Respuesta :

Following are the python program to calculate the factorial value:

Program:

factorial=1 #declare a variable.  

number=int(input("Enter a positive integer:")) #input a number.  

while (number>0): #loop  

   factorial= factorial*number # holding value in factorial variable  

   number=number-1  

print('=',factorial) #print value.


Program Explanation:


The description of the above python program can be given as:

  • In the above program firstly we define a variable that is "factorial".
  • In this variable, we assign a value that is 1 and it is used to calculate the factorial value.  
  • We define a variable "number". The number variable is used to take input from the user.  
  • Then we define a loop in the loop we calculate the factorial and hold the value in the factorial value in the last we print the value.  

Output:

Enter a positive integer: 6  

= 720  

Find out more information about the factorial here:

brainly.com/question/1483309

ACCESS MORE