Skip to content

Question 19

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

1
2
3
4
5
6
7
scores = [90, 75, 60]
score_diff = (
    abs(scores[0]-scores[1]),
    abs(scores[2]-scores[0]),
    abs(scores[2]-scores[1]),
)
print(score_diff)
Solution

Initialize variable scores with list [90, 75, 60]. We also now initialize variable score_diff to be a tuple containing 3 values:

  • abs(scores[0]-scores[1]): abs(90-75) = abs(15) = 15
  • abs(scores[2]-scores[0]): abs(60-90) = abs(-30) = 30
  • abs(scores[2]-scores[1]): abs(60-75) = abs(-15) = 15

score_diff is the tuple (15, 30, 15).

Answer
(15, 30, 15)