Python Program

Python Factorial | How to implement in 1 easy way


Python Factorial is the product of the every number less than the provided number until 1, they are mostly used in power series in mathematics.

The formula to calculate the python factorial is n! = n. (n-1) ! we will see a example program how the factorial is calculated for any given number.

First step is to collect the user input as below

num = int(input("Enter a number: "))

Considering a variable fact and assigning it with initial value as 1. And further calculated values are stored in this variable.

fact = 1

Let us run a for loop providing the inputs as 1 and num + 1 as parameters

for i in range(1, num + 1):

And the save the value into the variable fact

fact *= i

Finally print the values as below using a print statement.

print("Factorial of", num, "is", fact)

Full Code :

num = int(input("Enter a number: "))

fact = 1
for i in range(1, num + 1):
    fact *= i

print("Factorial of", num, "is", fact)
Abhishek

Share
Published by
Abhishek

Recent Posts

HTML: The Evolution and Power of Unleashed Web Language and Modern too

IntroductionInitial StagesEvolutionChallenging Other LanguagesCurrent TrendsAI and HTMLConclusion Introduction HTML, or HyperText Markup Language, is the…

2 months ago

Increase in 80C in Budget 2024 ?

Increase in 80CDemands and Discussions: Increase in 80C Section 80C of the Income Tax Act…

2 months ago

ChatGPT 4o Unleashing the Power of GPT A Comprehensive Guide

IntroductionWhat is ChatGPT-4?Key Features of ChatGPT-4Enhanced Natural Language UnderstandingImproved Response GenerationVersatilityApplications of ChatGPT-4Customer SupportContent CreationEducational…

4 months ago

APJ Abdul Kalam Biography: A Tribute to India’s Powerful Missile Man

APJ Abdul Kalam Biography :Childhood :Academics :Professional Career :Achievements : APJ Abdul Kalam Biography :…

7 months ago

Srinivasa Ramanujan Biography: Exploring the Genius

We value your feedback! Please share your thoughts on this blog on Srinivasa Ramanujan Biography…

7 months ago

Interim Budget 2024: What to Expect Any Rise

Interim Budget 2024 :Importance :Key Points :Rise in 80 C ?Standard Deduction : Interim Budget…

8 months ago

This website uses cookies.