0
Explain the code it prints 120 how?
b=3 a=1 for i in range(5): a=a+a*i print(a)
3 Respuestas
+ 11
Initially a = 1
for i = 0
a = 1 + 1 * 0 = 1
Now a = 1
for i = 1
a = 1 + 1 * 1 = 1 + 1 = 2
Now a = 2
for i = 2
a = 2 + 2 * 2 = 2 + 4 = 6
Now a = 6
for i = 3
a = 6 + 6 * 3 = 6 + 18 = 24
Now a = 24
for i = 4
a = 24 + 24 * 4 = 24 + 96 = 120
finally when for loop ends a is 120.
+ 4
a=1+1*0 #1
a=1+1*1 #2
a=2+2*2 #6
a=6+6*3 #24
a=24+24*4 #120
that's why it prints 120
+ 3
What does b do?