Computer Science, asked by aditi9540, 1 year ago

a WAP to input a number and print its factorial.
factorial of 5 = 1 x 2 x 3 x 4 x 5 = 120​
python programming

Answers

Answered by fiercespartan
9

To find the factorial of a number, we will need to multiply all the numbers less than the number and greater than 0.

For example, if the number is 5, we have to multiply 5,4,3,2,1

So, we will take an input from the user, use a while loop and keep the condition as until the number is greater than 1 and we will decrease the value of the number every time.

CODE:

number = int(input())

factorial = 1

while number > 1:

   factorial = factorial * number

   number = number - 1

Answered by gaganadithyareddy9
0

Answer:

Hey! Here is your code...

def factorial(n):

   prod = 1

   

   while n>=1:

       prod*=n

       n = n-1

       

   return prod

x = int(input("Enter a number: "))

f = factorial(15)

print("Factorial of", x, '=', f)

# HOPE THIS HELPS!!

Similar questions