Questions
Write a python program to display the factorial of a given number.
Last Updated : 26 Jul 2026
Jul 22, Jan 23, Jan 24, Jul 24
Solution:
# Python program to find the factorial of a given number
# Take input from the user
num = int(input("Enter an integer: "))
# Initialize the factorial variable to 1
factorial = 1
# Check if the number is negative, zero, or positive
if num < 0:
print("Factorial does not exist for negative numbers.")
elif num == 0:
print("The factorial of 0 is 1")
else:
# Loop from 1 to num (inclusive) to calculate the product
for i in range(1, num + 1):
factorial *= i
print(f"The factorial of {num} is {factorial}")
Report an error