Find extra long factorials in python

Upasana | September 03, 2019 | 1 min read | 248 views | Python Coding Problems


The factorial of the integer n, written n!, is defined as:

\$n! = n*(n-1)*(n-2)*..*3*2*1\$

Calculate and print the factorial of a given integer.

Input Format

Input consists of a single integer n.

Constraints
\$1<=n<=100\$
Output Format

Print the factorial of n.

Sample Input
25
Sample Output
15511210043330985984000000

Explanation

\$25! = 25*24*23*22*...*3*2*1\$

Solution

Note

This answer passes all the tests

We are going to keep logic in main function only such that we are able to build array as we will be getting data from input. You shall create a script.py file and paste the below code in it.

1st line: arr = int(input()) This takes input from command line. Please note that input type is going to be in string format and we have to use int() to convert from string to int

2nd line: a=1 This is to intialize the number.

Finding extra long factorial of a number: python
if __name__ == '__main__':
    arr = int(input())
    a = 1
    for i in range(1,arr+1):
        a = a*i
    print(a)

Top articles in this category:
  1. Python coding challenges for interviews
  2. Send rich text multimedia email in Python
  3. Flask Interview Questions
  4. Find perfect abundant or deficient factors in python
  5. python problem 1: find the runner-up score
  6. Sequence of Differences in Python
  7. Python send GMAIL with attachment

Recommended books for interview preparation:

Find more on this topic:
Buy interview books

Java & Microservices interview refresher for experienced developers.