#Python Daily Programming | Day-1 | Basic #Programming | #Factorial of Number
Welcome to the Python Daily Programming series. In this series we will upload the daily one python program. So you will get the daily new python program. I will upload the daily Python Program with an explanation at 5:00:PM.
I have more than 300+ program ideas. I will start from very basic and will go to advance day by day. I will try to upload it every day. The programs that I will upload daily is
📌 Basic Program
📌 Array Programs
📌 List Programs
📌 Tuple, Dictionary, Set Programs
📌 File handling, Regex, Date time program
📌 Sorting and algorithm programs
📌 Image processing & OpenCV programs
Today is the 1st day of it, We are going to learn about Factorial Program
Program - 1 Factorial of Number using Python
We need to first understand what is the factorial, wo if someone asks what is the factorial of 5, then you just need to do fact(5) = 5*4*3*2*1. So answer will be 120. So now we are implementing this logic into our Python program.
def factorial_of_num(number):
fact = 1
# Check if the number is negative, positive or zero
if number < 0:
print("Factorial of negative number is not possible")
elif number == 0:
print("The Factorial of 0 is 1")
else:
for i in range(1, number + 1):
print(str(fact)+' =',str(fact),'*',str(i))
fact = fact * i
''' Loop explanation
fact is 1, we have initialized
now
if we want to find factorial for 4
then it should be like
1 = 1*1 - 1st Iteration
1 = 1*2 - 2nd Iteration
2 = 2*3 - 3rd Iteration
6 = 6*4 - 4th Iteration
24 -> Loop will be end
'''
print(fact)
print("The factorial of", number, "is", fact)
## Let's make a function call
factorial_of_num(4)
See full tutorial on the YouTube, Dont't forget to Subscribe the channel
Comments
Post a Comment