Back to Coding

Coding: trace, predict and fix programs

Questions at easy, medium and hard levels. Pick a level and get a fresh set every time, with instant feedback.

Learn it To trace a program, keep a small table of every variable and update it one line at a time. A loop repeats its indented lines; an if-statement runs its lines only when the condition is true. To fix a program, find the first line where the table stops matching what the program should do.

Example: x = 3, then repeat 4 times: x = 2 * x − 1. What is x at the end?

  1. Start: x = 3.
  2. Loop 1: 2(3) − 1 = 5. Loop 2: 2(5) − 1 = 9. Loop 3: 2(9) − 1 = 17. Loop 4: 2(17) − 1 = 33.

Loading questions…