please i need help on how the answer to this question is 300 | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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))

1st Oct 2018, 9:04 PM
āœ³AsterisKāœ³
āœ³AsterisKāœ³ - avatar
4 Respostas
+ 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
2nd Oct 2018, 3:21 PM
danvetio
danvetio - avatar
+ 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
1st Oct 2018, 9:25 PM
KrOW
KrOW - avatar
+ 1
thanks man
1st Oct 2018, 9:27 PM
āœ³AsterisKāœ³
āœ³AsterisKāœ³ - avatar
+ 1
šŸ‘šŸ‘šŸ‘
1st Oct 2018, 9:27 PM
KrOW
KrOW - avatar