Write a python program using functions …
CBSE, JEE, NEET, CUET
Question Bank, Mock Tests, Exam Papers
NCERT Solutions, Sample Papers, Notes, Videos
Posted by Nabaneet Das 4 years, 1 month ago
- 1 answers
Related Questions
Posted by Hanni Pham 4 months, 1 week ago
- 1 answers
Posted by Kandeepan Jothivel 6 months, 3 weeks ago
- 2 answers
Posted by Hanni Pham 4 months, 1 week ago
- 0 answers
Posted by Prawar Narang 6 months, 2 weeks ago
- 1 answers
Posted by Manoj Kumar Manoj Kumar 7 months, 2 weeks ago
- 0 answers
Posted by Syedali Fathima 5 months, 3 weeks ago
- 1 answers
Posted by Priya Shukla 5 months, 2 weeks ago
- 1 answers
myCBSEguide
Trusted by 1 Crore+ Students
Test Generator
Create papers online. It's FREE.
CUET Mock Tests
75,000+ questions to practice only on myCBSEguide app
Gaurav Seth 4 years, 1 month ago
Find factorial using Python function – using for loop
#Pyton program to find factorial of a number
def factorial(num):#function definition
fact=1
for i in range(1, num+1):#for loop for finding factorial
fact=fact*i
return fact #return factorial
number=int(input("Please enter any number to find factorial: "))
result=factorial(number)#function call and assign the value to variable result
print("The factorial of %d = %d"%(number,result))
When the above code is executed, it produces the following results
Please enter any number to find factorial: 6
The factorial of 6 = 720
Find factorial using Python function – using while loop
def factorial(num):#function definition
fact=1;
i=1
while i<=num:
fact=fact*i
i=i+1
return fact
num=input("Enter a number..");
result=factorial(num)
print("factorial of the number: %d" %result)
factorial(num)#function call
When the above code is executed, it produces the following results
Enter a number..5
factorial of the number: 120
Programming approaches for implementing these program
1Thank You