0% found this document useful (0 votes)
4 views1 page

Python Programs

The document provides three methods to calculate the factorial of a number in Python: using a for loop, a while loop, and a function. Each method initializes a variable for the factorial and iterates through a range or while condition to compute the result. The final output displays the calculated factorial for a given number input by the user.

Uploaded by

baishwarn
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Python Programs

The document provides three methods to calculate the factorial of a number in Python: using a for loop, a while loop, and a function. Each method initializes a variable for the factorial and iterates through a range or while condition to compute the result. The final output displays the calculated factorial for a given number input by the user.

Uploaded by

baishwarn
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

calculate the factorial of a number in Python using for loop

fact=1
n=5
for i in range(1,n+1):
fact=fact*i
print(fact)

calculate the factorial of a number in Python using while loop

fact,n,i=1,5,1
while(i<=n):
fact=fact*i
i=i+1
print(fact)

calculate the factorial of a number in Python using function

import os
[Link]('cls')
def fact(m):
fact,i=1,1
while(i<=n):
fact=fact*i
i=i+1
return(fact)
n=int(input("enter no"))
s=fact(n)
print("Factorial is",s)

You might also like