PY
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
num = int(input())
def fibonacci(n):
#complete the recursive function
global set1, set2
try:
set1
except NameError:
set1, set2 = set(), set()
if n <= 1:
set1.add(n)
return n
res = fibonacci(n - 1)
set2.add(res)
if n == num:
for i in sorted(set1):
print(i)
for i in sorted(set2):
print(i)
return fibonacci(n - 2) + res
fibonacci(num)
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run