+ 2
please i need help on how the answer to this question is 300
def f(n): if n==0: return 0 else: return f(n-1) + 100 print(f(3))
4 ответов
+ 5
n=0, f(0)=0
n=1, f(1)= f(0) + 100 = 0 + 100 =100
n=2, f(2)=f(1) + 100 = f(0) + 100 + 100 = 200
n=3, f(3)=f(2) + 100 = f(1) + 100 +100 = f(0) +100 + 100 +100 = 300
result is 300
+ 4
f(3) = f(2) + 100
f(2) = f(1) + 100
f(1) = f(0) + 100
f(0) = 0
then going back and resolving (f(0) is yet resolved to 0):
f(1)= 0+100= 100
f(2)= 100 + 100= 200
f(3)= 200+100= 300
+ 1
thanks man
+ 1
👍👍👍