Factorial of the Number in Python Using While Loop

(Last Updated On: 09/12/2022)

Python Program to Find Factorial of the Number Using While Loop

# Find Factorial of the Number in Python Using While Loop
# accept input number from user
n = int(input("Enter any number: "))

# logic to calculate the factorial of a number
f = 1
while n >= 1:
    f *= n
    n -= 1

# print output
print("Factorial is", f)

Output:

Enter any number: 5
Factorial is 120

Leave a Reply

Your email address will not be published. Required fields are marked *