Find extra long factorials in python

Carvia Tech | September 03, 2019 | 1 min read | 3 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. Python Flask Interview Questions
  3. Top 100 interview questions on Data Science & Machine Learning
  4. Google Data Scientist interview questions with answers
  5. Sequence of Differences in Python
  6. python problem 1: find the runner-up score
  7. Send email with attachment in Python



Find more on this topic:
Machine Learning image
Machine Learning

Data science, machine learning, python, R, big data, spark, the Jupyter notebook, and much more

Last updated 1 week ago


Recommended books for interview preparation:

This website uses cookies to ensure you get the best experience on our website. more info