Question 5 of 22intermediate🔧 ApplyShort Answer2 marks

Write the output of the following:

(a)

num1 = 4 num2 = num1 + 1 num1 = 2 print (num1, num2)

Answer

2 5

(b)

num1, num2 = 2, 6 num1, num2 = num2, num1 + 2 print (num1, num2)

Answer

6 4

(c)

num1, num2 = 2, 3 num3, num2 = num1, num3 + 1 print (num1, num2, num3)

Answer

Error

Explanation

For part (a), the variable num1 is initialized to 4. num2 is calculated as 5 (4+1). Subsequently, num1 is reassigned to 2. The print statement displays the final values: 2 and 5. For part (b), num1 and num2 are initialized to 2 and 6. In the statement num1, num2 = num2, num1 + 2, the right-hand side is evaluated first using current values. This yields 6 and 4. These values are then assigned to num1 and num2 respectively.

For part (c), num1 and num2 are initialized. The next line attempts to calculate num3 + 1. Since num3 has not been defined or assigned a value previously, the program will raise an error.