Factorial of the Number in Python Using for Loop

(Last Updated On: 09/12/2022)

Python Program to Find Factorial of the Number Using for Loop

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

f = 1

# for loop to calculate factorial of a number
for i in range(n, 0, -1):
    f *= i

# 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 *