+ 1

how to explan this......the result is 8

def f(x): if x==0 or x==1: return 1 else: return f(x-1)+f(x-1) print (f(4))

24th Dec 2019, 4:09 PM
yq w
2 odpowiedzi
+ 2
f(4) = f(3) + f(3) = f(2) + f(2) + f(2) + f(2) = f(1) + f(1) + f(1) + f(1) + f(1) + f(1) + f(1) + f(1) = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 4 + 4 = 8
24th Dec 2019, 4:34 PM
r1c5
r1c5 - avatar
+ 2
| return 1 | | f(1) + f(1) | | f(2) + f(2) | | f(3) + f(3) | ------------------ f(1) + f(1) = 1 + 1 = 2 f(2) + f(2) = 2 + 2 = 4 f(3) + f(3) = 4 + 4 = 8 Please correct me if I'm wrong.
24th Dec 2019, 4:21 PM
Avinesh
Avinesh - avatar