Python Practice › Loop Programs › Program 30

Factorial with a loop

EasyLoop Programs · 30 of 90

Write a Python program to calculate the factorial of a number using a loop.

Advertisement
Input
7
Output
7! = 5040

Approach

  1. Multiply 1 × 2 × … × n.

Solution

Python
n = 7fact = 1for i in range(1, n + 1):    fact *= iprint(f"{n}! = {fact}")
Output
7! = 5040

Learn the concept

New to this topic? Read the lesson, then come back.

More loop programs

← All 90 Loop Programs

Leave a Comment