Python Program to Find Super Factorial of a Number
In the previous article, we have discussed Python Program to Calculate the Value of nPr
Super factorial :
Super factorial of a number is obtained by multiplying the first N factorials of a given Number.
Given a number, and the task is to find the superfactorial of an above-given number.
Examples:
Example1:
Input:
Given Number = 5
Output:
The super Factorial value of above given number = 34560
Example 2:
Input:
Given Number = 4
Output:
The super Factorial value of above given number = 288
Program to Find SuperFactorial of a Number.
Below are the ways to find SuperFactorial of a given Number.
Method #1: Using For loop (Static Input)
Approach:
- Import math module using the import keyword.
- Give the number as static input and store it in a variable.
- Take a variable and initialize its value with ‘1’.
- Loop from ‘1 ‘ to the above-given number using For loop.
- Calculate the factorial of the iterator value using the built-in factorial method and multiply it with the above-initialized superfactorial value.
- Store it in another variable.
- Print the superfactorial value of the above-given number.
- The Exit of the program.
Below is the implementation:
# Import math module using the import keyword. import math # Give the number as static input and store it in a variable. gvn_numbr = 5 # Take a variable and initialize it's value with '1'. supr_factrl = 1 # Loop from '1 ' to above given number using For loop. for iteror in range(gvn_numbr+1): # Calculate the factorial of the iterator value using built-in factorial method # and multiply it with above initialized superfactorial value. # Store it in another variable. supr_factrl = supr_factrl * math.factorial(iteror) # Print the superfactorial value of the above given number. print("The super Factorial value of above given number = ", supr_factrl)
Output:
The super Factorial value of above given number = 34560
Method #2: Using For Loop (User input)
Approach:
- Import math module using the import keyword.
- Give the number as User input and store it in a variable.
- Take a variable and initialize its value with ‘1’.
- Loop from ‘1 ‘ to the above-given number using For loop.
- Calculate the factorial of the iterator value using the built-in factorial method and multiply it with the above-initialized superfactorial value.
- Store it in another variable.
- Print the superfactorial value of the above-given number.
- The Exit of the program.
Below is the implementation:
# Import math module using the import keyword. import math # Give the number as User input and store it in a variable. gvn_numbr = int(input("Enter some Random Number =")) # Take a variable and initialize it's value with '1'. supr_factrl = 1 # Loop from '1 ' to above given number using For loop. for iteror in range(gvn_numbr+1): # Calculate the factorial of the iterator value using built-in factorial method # and multiply it with above initialized superfactorial value. # Store it in another variable. supr_factrl = supr_factrl * math.factorial(iteror) # Print the superfactorial value of the above given number. print("The super Factorial value of above given number = ", supr_factrl)
Output:
Enter some Random Number = 4 The super Factorial value of above given number = 288
Explore more instances related to python concepts from Python Programming Examples Guide and get promoted from beginner to professional programmer level in Python Programming Language.
Python Program to Find Super Factorial of a Number Read More »