Iterative approach:

def calculate_factorial(n):
    factorial = 1
    for i in range(1, n + 1):
        factorial *= i
    return factorial

Recursive:

def calculate_factorial(n):
    if n == 0:
        return 1
    else:
        return n * calculate_factorial(n-1)

It would be great if you could share the code that you tried.

Answer from DASH on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-program-for-factorial-of-a-number
Factorial of a Number - Python - GeeksforGeeks
Given an integer n, the task is ... and combinatorics. For Example: Input: n = 6 Output: 720 Explanation: 6! = 6 × 5 × 4 × 3 × 2 × 1 = 720 · Let's explore different methods to find the factorial of a number in ...
Published   November 29, 2025
🌐
Vultr
docs.vultr.com › python › examples › find-the-factorial-of-a-number
Python Program to Find the Factorial of a Number | Vultr Docs
December 27, 2024 - For example, the factorial of 5 (denoted as 5!) is calculated as 5 * 4 * 3 * 2 * 1, which results in 120. Factorials are commonly used in permutations, combinations, and other statistical calculations.
🌐
GeeksforGeeks
geeksforgeeks.org › python › factorial-in-python
factorial() in Python - GeeksforGeeks
The factorial of a number n (written as n!) is the product of all positive integers from 1 to n. ... Python provides a function math.factorial() that computes factorial without writing the entire loop manually. ... Parameters: x -> number whose factorial you want (must be a non-negative integer). Example 1: This example uses math.factorial() to compute factorial directly using Python’s inbuilt function.
Published   December 18, 2025
🌐
Programiz
programiz.com › python-programming › examples › factorial
Python Program to Find the Factorial of a Number
# Python program to find the factorial ... from the user # num = int(input("Enter a number: ")) # call the factorial function result = factorial(num) print("The factorial of", num, "is", result)...
🌐
AlmaBetter
almabetter.com › bytes › articles › factorial-program-in-python
Factorial Program in Python(Factorial of a Number in Python)
October 19, 2024 - Learn to write a factorial program in Python using for loops, while loops, recursion, and functions with code examples, detailed explanations and use cases ... The factorial of a number is an essential concept in mathematics and programming. It is denoted as n!, which represents the product of all positive integers from 1 to n. For example, the factorial of 5 (written as 5!) is calculated as:
🌐
w3resource
w3resource.com › python-exercises › python-functions-exercise-5.php
Python Exercise: Calculate the factorial of a number - w3resource
Factorial of 5: 120 Factorial of -12: Number can't be negative or floating point! Factorial of 1.22: Number can't be negative or floating point! Factorial of 100: 93326215443944152681699238856266700490715968264381621468592963895217599993229...
🌐
Vultr
docs.vultr.com › python › examples › find-factorial-of-number-using-recursion
Python Program to Find Factorial of Number Using Recursion | Vultr Docs
November 21, 2024 - number = 5 if number >= 0: print("Factorial of", number, "is", factorial(number)) else: print("Enter a positive integer") Explain Code · This script sets a number 5 then checks if it's non-negative before calling the factorial function.
Find elsewhere
🌐
PYnative
pynative.com › home › python › programs and examples › python programs to find factorial of a number
Python Find Factorial of a Number [5 Ways] – PYnative
March 31, 2025 - ... In this example, we are applying the lambda function (x * y) to all values in the list [1, 2, 3, 4]. So, the output is 24 (1*2*3*4). from functools import reduce n = 5 if n < 0: print("Factorial not defined for negative numbers") factorial = reduce(lambda x, y: x * y, range(1, n + 1), 1) ...
🌐
Codingem
codingem.com › home › factorial with a while loop in python
Factorial with a While Loop in Python - codingem.com
April 10, 2023 - print(factorial(5)) Output: 120 · You now know what is the factorial of a number and how it is commonly calculated using recursion. But there are some alternatives, that is: A built-in function · While loop · For loop · Let’s go through ...
🌐
W3Schools
w3schools.com › python › ref_math_factorial.asp
Python math.factorial() Method
The factorial of a number is the ... 1. For example, the factorial of 6 would be 6 x 5 x 4 x 3 x 2 x 1 = 720 ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ...
🌐
WsCube Tech
wscubetech.com › resources › python › programs › factorial
Python Program to Find Factorial of a Number (Factorial Code)
October 28, 2025 - Learn how to write a Python program to find the factorial of a number. Understand efficient factorial code to solve factorial problems quickly and easily.
🌐
Tutorial Gateway
tutorialgateway.org › python-program-to-find-factorial-of-a-number
Python Program to find Factorial of a Number
March 31, 2025 - number = int(input(" Please enter any Number : ")) fact = 1 for i in range(1, number + 1): fact = fact * i print("The factorial of %d = %d" %(number, fact)) The user entered integer in the above program example is 4. Please refer to math functions, ...
🌐
Great Learning
mygreatlearning.com › blog › it/software development › python program to find the factorial of a number
Python Program to Find the Factorial of a Number
October 24, 2024 - ... Factorial of a number is denoted by n! is the product of all positive integers less than or equal to n: ... So what is 10!? Multiply 10 with all the positive integers which are less than 10. ... To find '5!' again, do the same process.
🌐
Shiksha
shiksha.com › home › it & software › it & software articles › programming articles › how to find the factorial of a number using python
How to Find the Factorial of a Number Using Python - Shiksha Online
August 16, 2024 - How to Find the Factorial of a Number Using Python ... In this article, we will discuss different methods to find the factorial of a number in python using for, while, ternary operator and math module. While practicing Python programming as a beginner, or even during Python interviews, one of the most common programs you will be asked to write is going to be Python factorial.
🌐
Unstop
unstop.com › home › blog › factorial program in python | examples & complexity analysis
Factorial Program In Python | Examples & Complexity Analysis
February 4, 2025 - ... # Function to find factorial ... return n * factorial_recursive(n - 1) # Example usage number = 5 print(f"The factorial of {number} is {factorial_recursive(number)}")...
🌐
Simplilearn
simplilearn.com › home › resources › software development › factorial program in python: explained with examples
Factorial Program in Python: Explained with Examples
November 9, 2023 - Learn to code a factorial program in Python with our easy guide. Master loops & recursion techniques for your coding toolbox. Continue reading!
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Python Guides
pythonguides.com › factorial-of-a-number-in-python
Factorial Of A Number In Python
March 20, 2025 - Check out Download and Extract ZIP Files from a URL Using Python · Recursion provides an efficient way to calculate factorials that mirrors the mathematical definition: def factorial_recursive(n): """Calculate factorial using recursion.""" if n < 0: raise ValueError("Factorial is not defined for negative numbers") # Base case if n == 0 or n == 1: return 1 # Recursive case return n * factorial_recursive(n - 1) # Example usage number = 6 print(f"The factorial of {number} is: {factorial_recursive(number)}")