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
easyTrace this code: SET age = 15. IF age >= 18 THEN OUTPUT 'Adult' ELSE OUTPUT 'Minor'.
Example 2
mediumWrite pseudocode using IF-ELIF-ELSE to assign a grade: 90+ = A, 80โ89 = B, 70โ79 = C, below 70 = F.
Example 3
easyWhat is the output? SET temp = 25. IF temp > 30 THEN OUTPUT 'Hot' ELIF temp > 20 THEN OUTPUT 'Warm' ELSE OUTPUT 'Cold'.
Example 4
mediumTrace 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?