Pseudocode CS Thinking Example 2

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

Example 2

medium
Convert the following Python code to pseudocode: total = 0; for i in range(1, 11): if i % 2 == 0: total += i; print(total).

Solution

  1. 1
    Step 1: SET total = 0.
  2. 2
    Step 2: FOR i = 1 TO 10: IF i MOD 2 == 0 THEN total = total + i.
  3. 3
    Step 3: OUTPUT total. The pseudocode removes Python-specific syntax (range, +=, print) and replaces it with universal keywords (FOR, IF, OUTPUT, MOD).

Answer

SET total = 0. FOR i = 1 TO 10: IF i MOD 2 == 0 THEN total = total + i. OUTPUT total. Result: 30 (sum of 2+4+6+8+10).
Pseudocode bridges the gap between human thinking and actual code. It uses standard keywords (IF, FOR, WHILE, INPUT, OUTPUT) that map naturally to any programming language.

About Pseudocode

An informal, human-readable description of an algorithm using structured language that resembles code but is not tied to any specific programming language. Pseudocode uses plain English mixed with programming constructs like IF, WHILE, and FOR to describe logic without worrying about syntax rules.

Learn more about Pseudocode โ†’

More Pseudocode Examples