# What do you do if you don't understand the code logic?

• Please explain the code logic. I don't understand what happens under the hood:

``````def F(n):
if n > 2:
return F(n-1)+ G(n-2)
else: return 1
def G(n):
if n > 2:
return G(n-1) + F(n-2)
else: return 1
print(F(7))
``````

• Add the good information, it'll be a little clearer:

``````def F(n):
if n > 2:
print(f"F({n}): calling F({n-1}) + G({n-2})")
return F(n-1)+ G(n-2)
else:
print(f"G({n}): return 1")
return 1
def G(n):
if n > 2:
print(f"G({n}): calling G({n-1}) + F({n-2})")
return G(n-1) + F(n-2)
else:
print(f"G({n}): return 1")
return 1
print(F(7))
``````

Conclusion:

``````F(7): calling F(6) + G(5)
F(6): calling F(5) + G(4)
F(5): calling F(4) + G(3)
F(4): calling F(3) + G(2)
F(3): calling F(2) + G(1)
G(2): return 1
G(1): return 1
G(2): return 1
G(3): calling G(2) + F(1)
G(2): return 1
G(1): return 1
G(4): calling G(3) + F(2)
G(3): calling G(2) + F(1)
G(2): return 1
G(1): return 1
G(2): return 1
G(5): calling G(4) + F(3)
G(4): calling G(3) + F(2)
G(3): calling G(2) + F(1)
G(2): return 1
G(1): return 1
G(2): return 1
F(3): calling F(2) + G(1)
G(2): return 1
G(1): return 1
13
``````

2

2

2

2

2

2

2

2

2

2

2

2

2

2

2