9: Recursion in python
9: Recursion in python
Recursive Method for Calculating Factorial
Task
Write a factorial function that takes a positive integer, as a parameter and prints the result of ( factorial).
Note: If you fail to use recursion or fail to name your recursive function factorial or Factorial, you will get a score of .
Input Format
A single integer, (the argument to pass to factorial).
Constraints
- Your submission must contain a recursive function named factorial.
Output Format
Print a single integer denoting .
Solution:
#!/bin/python3
import math
import os
import random
import re
import sys
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
n = int(input())
print(factorial(n))
Comments
Post a Comment