Factorial of a number in Python

Factorial of a number is product of all integers from 1 up to the number ( inclusive ).
Factorial of 5 is 1*2*3*4*5 = 120
Or
n! = 1*2*3….n

Factorial of a number by using loop and by recursive functions in Python

Factorial of an input number by using loop

We used for loop here
a=int(input("Enter a number : "))
b=1
for i in range(1,a+1):
  b=b*i
print("Factorial : ", b)
Output
Enter a number : 6
Factorial :  720

Factorial of a number by using recursive function

Factorial using recursive function
By using recursive function we can call the function itself from within the function.
def fact(n):
  if n==1:
    return 1
  else:
    result=n* fact(n-1)
    #print("Part factorial : ", result)
    return result
fact(4)
Output
24

All Sample codes Fibonacci series Armstrong Number

Podcast on Python Basics


Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer