Skip to content
IGCSE·Tuition

Tools

Safe Python reasoning sandbox

Python code can run without errors and still print the wrong answer, and that gap is where most marks are lost.

On this page
  1. How do you use it?
  2. How do you read the result?
  3. Example walk-through
  4. What are the assumptions and limits?
  5. Which lessons explain the result?

Everything you enter stays on this device. Nothing is sent to us.

This page holds a tiny Python-like interpreter and five short exercises. You run the code, the tool compares the output with the expected output, and if the test fails it gives questions to think about.

It is for building the habit of reasoning about code, not just running it.

How do you use it?

  1. Pick an exercise. Read the one-line brief, for example “The program should print 15.”
  2. Predict the output before you touch the button. Write down what you think will appear.
  3. Press Run and test. Reset returns the first exercise.
  4. Read the result. If it passed, try to explain why. If it failed, use the “Think about it” questions, fix the code in the text box and run again.

Indent with spaces. The supported subset is listed under the code box: + - * / // % **, comparisons, and/or/not, print(), int(), str(), abs(), len(), min(), max(), if/elif/else, while, for … in range(…), break and continue.

How do you read the result?

You see your output on the left and the expected output on the right, with a message saying whether they match. Below that are the number of steps executed and the variables as they stood at the end.

If the safety limit stopped the code, a warning appears above the comparison. A stopped program still shows what it printed before the limit, which is often enough to spot the pattern.

Example walk-through

Open Sum of 1 to 5 (has a bug). The code adds n from range(1, 5) into total and prints it. The expected output is 15.

Run it. The output is 10 and the test fails. Read the first prompt: which numbers does range(1, 5) produce?

It gives 1, 2, 3, 4, because the stop value is not included. So total is 1 + 2 + 3 + 4 = 10, not 15.

Change the stop value to 6 and run again. The numbers are 1 to 5, the total is 15 and the test passes.

Next open Doubling until over 50. Start at x = 1 and double while x <= 50. The values go 2, 4, 8, 16, 32, 64.

At 64 the condition is false, so the loop ends and 64 prints. The condition checks the value before doubling, which is why the final value overshoots 50.

Then try Faulty loop: while True. It prints 0 forever, so the tool stops it at the limit. The brief asks you to make it print 0, 1, 2. Change the loop so n increases each pass and stops when n reaches 3, then run it.

What are the assumptions and limits?

  • It is a subset of Python. Division with / prints whole-number results without “.0”.
  • There are no user-defined functions, lists, string methods or imports.
  • Programs are capped at 60 lines and output is capped at 200 lines.
  • Runaway loops stop at 5000 steps or 300 ms.
  • It cannot see or change any file, and it makes no network request.
  • It is original practice only. It is not an exam environment and does not mark assessed work.

Which lessons explain the result?

For loops, read repair an off-by-one error, which explains exactly the range(1, 5) mistake above. The habit of predicting is taught in explain an expected result before running code, and identify an untested branch shows what passing one test does not prove.

To follow values through a function, see trace a returned value. The whole route is in Python transition and execution.

If you would like a teacher to go through your loops and tests with you, see online one-to-one Computer Science tuition. The pseudocode trace trainer is a good partner, and more tools are in the learning tools directory.

Questions people ask

Is this real Python?

It is a small interpreter for a Python-like subset that runs inside this page. It supports variables, arithmetic, comparisons, print, if/elif/else, while, for with range, break and continue, plus a few built-in functions. There are no functions you define, lists, imports or file access. Check the current syllabus for the Python your exam year expects.

What happens if my loop never ends?

The interpreter counts every step and also watches the clock. At 5000 steps or 300 milliseconds it stops your code, says so, and keeps the page responsive. Then ask the useful question: what inside the loop changes the thing the condition checks?

Can the sandbox touch my files or the internet?

It offers no file, network or import feature at all, so the code you type has nothing to reach with. We do not claim this is a formal security boundary. It simply has no dangerous features, so use it for short practice exercises only.

Why does the tool show an expected output?

So you can test your prediction. Good practice is to write down what you think will print before you run. If the tool says the test failed, the prompts under the result point you to the line to re-trace.

Sources

  1. Cambridge IGCSE Computer Science 0478 syllabus page

Updated:

Your next step

If you can write code that runs but cannot explain why it prints the wrong value, a one-to-one teacher can walk through your loop with you and build the habit of predicting first.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80. Other fees, schedules and ongoing arrangements are confirmed directly with your teacher after the trial class.

9,000+ students helped through our service