Python program to find the factorial of n numbers

Hello everyone, welcome to nkcoderz.com. In this article we will going to discuss about Python program to find the factorial of n numbers.

Here is an example of a Python program that calculates the factorial of a given number:

Code for python program to find the factorial of n numbers

def factorial(n):
    fact = 1
    for i in range(1, n+1):
        fact *= i
    return fact

n = int(input("Enter a number: "))
print("Factorial of", n, "is", factorial(n))

Output

Enter a number: 5
Factorial of 5 is 120

Explanation

In this program, the factorial(n) function takes one argument: a number n. The function uses a for loop to repeatedly multiply the current factorial value with the next integer value from 1 to n. At the end of the loop, the function returns the factorial of the given number n.

The program starts by asking the user to enter the number. This value is stored in the variable n. The function factorial is called with n as an argument. The returned value of the function is printed with message “Factorial of n is”.

It’s always a good practice to validate the input, in this case, make sure the entered number is not negative or zero.

Python Program To Find The Fibonacci Series

Conclusion

If you liked this post, then please share this with your friends and make sure to bookmark this website for more awesome content.


If You Like This Page Then Make Sure To Follow Us on Facebook, G News and Subscribe Our YouTube Channel. We will provide you updates daily.
Shares
facebook sharing button Share
twitter sharing button Tweet
whatsapp sharing button Share
telegram sharing button Share
pinterest sharing button Pin

Leave a Comment