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
#code presented in the task
num = int(input())
def fibonacci(n):
#complete the recursive function
fibonacci(num)
#my solution after some searching. NOTE: final line is a simple call of the function with the input value
num = int(input())
def fibonacci(n):
#complete the recursive function
if n<=1:
return n
else:
return fibonacci(n-1) + fibonacci(n-2)
for i in range(num):
print(fibonacci(i))
#does not feel right, using the FOR feels like cheating the idea of recursion
#the below code is from the lesson. NOTE: No FOR in the code
def factorial(x):
if x == 1:
return 1
else:
return x * factorial(x-1)
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run