Exercise 3.12. (Simultaneous Assignment)
1. Ensure you have viewed the video (associated with this exercise) at this link >>
2. For each of the following code examples produce a trace table and indicate the output displayed on the Visual Display Unit. Copy, paste and execute each program and check your answer for the Visual Display Unit output against the runtime. Check your trace table with a colleague, teacher or lecturer.
Exercise 13.12 Example 1
Exercise 13.12 Example 2
3. Consider the following code snippet:
a = 11
b = 22
a = b
b = a + b
After the execution of the last program statement of the above snippet a will have the value of 22 and b will have the value of 44.
Now consider the following snippet of code:
a = 11
b = 22
a, b = b, a + b
After the execution of the last program statement of the above snippet a will have the value of 22 and b will have the value of 33.
In the case of both snippets of code a has the value of 22 but the value of b differs even though in both cases b was assigned a + b. Explain in detail why this is the case.
a = 11
b = 22
a = b
b = a + b
After the execution of the last program statement of the above snippet a will have the value of 22 and b will have the value of 44.
Now consider the following snippet of code:
a = 11
b = 22
a, b = b, a + b
After the execution of the last program statement of the above snippet a will have the value of 22 and b will have the value of 33.
In the case of both snippets of code a has the value of 22 but the value of b differs even though in both cases b was assigned a + b. Explain in detail why this is the case.
END