Practice Variable in CS Thinking
Use these practice problems to test your method after reviewing the concept explanation and worked examples.
Quick Recap
A named container in a program that stores a value, which can be read, updated, or replaced.
A labeled box you can put things in, take things out, or change what's inside.
Example 1
easyTrace: SET x = 7. SET y = x + 3. SET x = y * 2. OUTPUT x, y.
Example 2
mediumShow how to swap the values of two variables a and b using a temporary variable. Trace with a = 5, b = 9.
Example 3
easyWhat is the output? SET score = 0. SET score = score + 10. SET score = score + 5. OUTPUT score.
Example 4
mediumTrace this swap algorithm: SET A = 3. SET B = 8. SET temp = A. SET A = B. SET B = temp. What are A and B at the end, and why is temp needed?