forked from AdaGold/core-problem-set-recursion
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpart-1.py
More file actions
42 lines (33 loc) · 797 Bytes
/
Copy pathpart-1.py
File metadata and controls
42 lines (33 loc) · 797 Bytes
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
# There are comments with the names of
# the required functions to build.
# Please paste your solution underneath
# the appropriate comment.
# factorial
def factorial(n):
if n == 0:
return 1
if n < 0:
raise ValueError
return n * factorial(n-1)
# reverse
def reverse(text):
if text == "":
return ""
if len(text) == 1:
return text
return reverse(text[1:]) + text[:1]
# bunny
def bunny(count):
if count == 0:
return 0
return 2 + bunny(count - 1)
# is_nested_parens
def is_nested_parens(parens):
if parens == "":
return True
else:
if parens[0] == "(" and parens[-1] == ")":
parens = is_nested_parens(parens[1:-1])
return parens
else:
return False