Variables and Assignments FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

A program uses variables hours and minutes.

hours ← 2
minutes ← 45
hours ← hours + 1

(a) What value does hours hold after the segment? (b) What value does minutes hold after the segment? (c) Explain in one sentence why changing hours did not change minutes.

Question 2 of 5

Trace the segment below.

red ← 3
blue ← 8
red ← blue
blue ← red

(a) What is red after all four statements? (b) What is blue after all four statements? (c) Explain why the final pair is not a successful swap of the original values 3 and 8.

Question 3 of 5

Write AP CSP pseudocode that swaps the values in alpha and beta using a temporary variable named hold.

(a) Write the three assignment statements in correct order. (b) Briefly justify why hold is needed. (c) Give one incorrect two-line attempt that fails to swap, and state what both variables hold afterward if alpha started as 10 and beta as 20.

Question 4 of 5

A game updates points as follows.

points ← 40
bonus ← 15
points ← points + bonus
bonus ← points
points ← bonus - 10

(a) What is points after the third statement? (b) What are points and bonus after the fifth statement? (c) Does the fifth statement restore the value points had after the first statement? Justify with numbers.

Question 5 of 5

The table shows intended meaning for three variables in a checkout program.

Variable Meaning
price cost of one item
qty number of items
total overall cost

(a) Write assignment statements that set price to 5, qty to 3, then total to price times qty. (b) Then assign price ← 7 without changing qty. What is total unless it is recalculated? (c) What additional assignment is needed so total matches the new price?