Skip to content

Question 12

What is the output of the following code? [3 marks]

1
2
3
4
balance, interest = 5000, 1.6
for _ in range(2):
    balance *= (1 + interest/100)
print(int(balance))
Solution

Variables balance and interest with values 5000 and 1.6 respectively are declared.

Count Count < 2? New balance: balance *= (1 + interest/100)
0 True 5000 * (1 + 1.6/100) = 5080
1 True 5080 * (1 + 1.6/100) = 5161.28
2 False 5161.28 (exit loop)

At the end, the integer value of balance is printed, i.e., int(5161.28) = 5161.

Answer
5161