Write the output of the following:
num1 = 4 num2 = num1 + 1 num1 = 2 print (num1, num2)
2 5
num1, num2 = 2, 6 num1, num2 = num2, num1 + 2 print (num1, num2)
6 4
num1, num2 = 2, 3 num3, num2 = num1, num3 + 1 print (num1, num2, num3)
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.