Skip to content

Question 11

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

1
2
3
4
5
x = 10
while x < 100:
    x += x

print(x)
Solution

A variable x with value 10 is declared.

x x < 100? New x: x += x
10 True 10 + 10 = 20
20 True 20 + 20 = 40
40 True 40 + 40 = 80
80 True 80 + 80 = 160
160 False 160 (exit loop)

At the end, the value of x is printed. During then, x = 160.

Answer
160