Dcoder icon

Learning Factorials with Loop/Recursion @ Dcoder

By Lochard | As a newbie programmer | 24 Jul 2023


Problem: If n is an integer greater than 0, n factorial (n!) is the product: n* (n-1) * (n-2) * ( n-3)… *

By convention, 0! = 1.

Write a Program to compute n Factorial(n!), where n is input. 

Input: n is a positive integer

Output: Output will be n factorial(n!)

Constraints: 0<=n<=12

Sample Input: 4

Sample Output: 

24

from functools import reduce
from operator import __mul__
print(reduce(__mul__, range(1, int(input())+1)))

How do you rate this article?

5


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.