Practice Selection in CS Thinking

Use these practice problems to test your method after reviewing the concept explanation and worked examples.

Quick Recap

Choosing which block of code to execute based on whether a condition is true or false.

If this is true, do that path. If it is false, take a different path instead.

Example 1

easy
Trace this code: SET age = 15. IF age >= 18 THEN OUTPUT 'Adult' ELSE OUTPUT 'Minor'.

Example 2

medium
Write pseudocode using IF-ELIF-ELSE to assign a grade: 90+ = A, 80โ€“89 = B, 70โ€“79 = C, below 70 = F.

Example 3

easy
What is the output? SET temp = 25. IF temp > 30 THEN OUTPUT 'Hot' ELIF temp > 20 THEN OUTPUT 'Warm' ELSE OUTPUT 'Cold'.

Example 4

medium
Trace this code: SET temp = 25. IF temp > 30 THEN fan = 'high' ELSE IF temp > 20 THEN fan = 'low' ELSE fan = 'off'. What is the value of fan?