-
Notifications
You must be signed in to change notification settings - Fork 21
/
Day9:_Recursion_3.py
86 lines (62 loc) · 1.66 KB
/
Day9:_Recursion_3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Day 9: Recursion
# Task
# Write a factorial function that takes a positive integer, N as a parameter and prints the result of N! (N factorial).
# Note: If you fail to use recursion or fail to name your recursive function factorial or Factorial, you will get a score of 0.
# Input Format
# A single integer, N (the argument to pass to factorial).
# Constraints
# 2 <= N <= 12
# Your submission must contain a recursive function named factorial.
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'factorial' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER n as parameter.
#
def factorial(n):
# Write your code here
if n < 1:
return None
if n == 1:
return 1
return n*factorial(n-1)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input().strip())
result = factorial(n)
fptr.write(str(result) + '\n')
fptr.close()
# Output Format
# Print a single integer denoting N!.
# Enter your code here. Read input from STDIN. Print output to STDOUT
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'factorial' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER n as parameter.
#
def factorial(n):
# Write your code here
if n < 1:
return None
if n == 1:
return 1
return n*factorial(n-1)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input().strip())
result = factorial(n)
fptr.write(str(result) + '\n')
fptr.close()