+ 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))
2 Respostas
+ 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
+ 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.