Selection CS Thinking Example 2

Follow the full solution, then compare it with the other examples linked below.

Example 2

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

Solution

  1. 1
    Step 1: Start with the highest threshold: IF score >= 90 THEN grade = 'A'.
  2. 2
    Step 2: ELIF score >= 80 THEN grade = 'B'. ELIF score >= 70 THEN grade = 'C'.
  3. 3
    Step 3: ELSE grade = 'F'. The conditions are checked in order, so the first match is used.

Answer

IF score >= 90: A. ELIF score >= 80: B. ELIF score >= 70: C. ELSE: F.
Chained selection (IF-ELIF-ELSE) handles multiple conditions. Order matters — conditions should go from most to least restrictive to avoid incorrect matches.

About Selection

Choosing which block of code to execute based on whether a condition is true or false. Selection allows programs to make decisions, following one path when a condition holds and a different path otherwise, using constructs like if, else-if, and else.

Learn more about Selection →

More Selection Examples