Practice Assignment in CS Thinking
Use these practice problems to test your method after reviewing the concept explanation and worked examples.
Quick Recap
The operation of storing a value in a variable. The variable name goes on the left, the value on the right.
Assignment is like putting a label on a box and putting something inside. The label is the variable name; the contents is the value.
Example 1
easyTrace the following code: SET x = 10. SET y = x. SET x = 20. OUTPUT x, y.
Example 2
easyWhat is the difference between `x = 5` (assignment) and `x == 5` (comparison)?
Example 3
easyWhat is the output? SET a = 3. SET b = 4. SET a = a + b. SET b = a - b. OUTPUT a, b.
Example 4
mediumTrace the values of x and y after each line:
SET x = 10
SET y = x + 5
SET x = y * 2
SET y = x - y
What are the final values of x and y?