Recursive Factorial

Lab Python Intermediate 20 points

Write a recursive fact(n) and print fact(n).

Input

One integer 0–50.

Output

n!

Example

Input

5

Output

120
Sample input available Sample output available
Editor
Python

Hints

Every recursion needs a base case that stops it.

n! = n × (n−1)!

Solution explanation

A recursive function solves a smaller version of the same problem until it reaches the base case.

Show solution
def fact(n):
    if n <= 1:
        return 1
    return n * fact(n - 1)


print(fact(int(input())))
Output
Answer
HOME LEARN COMMUNITY DASHBOARD