Write A Python Program To Calculate Factorial Of Given Number Using Function
Hi Programmers, welcome to my blog, lets try to get python solution for write a python program to calculate factorial of given number using function.
Title :
Python Problem : Write A Python Program To Calculate Factorial Of Given Number Using FunctionDescription :
Lets define a function and take a temp variable initialize it to 1. Then using for loop traverse from 2 to n and find the factorial of a number by multiplying the temp with index. Return the temp as factorial, nan
Code :
def fact(n): temp = 1 for index in range(2, n + 1): temp = temp * index return temp x = int(input("Enter a number : ")) if x >= 0: print("Factorial of number is %d" % fact(x)) else: print("Factorial of number is not possible !")
Conclusion :
Once you are done with reading the above code, open your python editor, try to write the program by yourself. This will improve your coding skills, try changing variable names, change operators and execute it.
Thank you for reading my article about write a python program to calculate factorial of given number using function if you have any queries about above solution, please comment down below, if you like this article share it with your friends.
0 Comments