Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 0.1 — What a Program Is
Python · Example 3 of 3

A bug: it runs, but the answer is wrong

The program has a mistake on the line marked bug. Python does not complain, because the grammar is fine. Fix it so the total is 42.

A program is a list of exact instructions that a computer follows in order. Almost every program takes some input, does some processing, and produces output; the text you write is called source code, and a mistake in it is called a bug.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write a program that prints the three steps for brushing your teeth, one per line, in the correct order.

02

Write a program that remembers the prices of a pen (10) and a notebook (45), adds them, and prints Total: 55.

03

This program should print the cost of three pencils at 5 each, but it prints 10. Find and fix the bug: pencil = 5 then cost = pencil + pencil then print("Cost:", cost).

Explain it without notes

01

In your own words, what is a program?

02

What are the three parts that almost every program has? Give an example of each for a calculator app.

03

What is a bug, and why can't the computer find every bug for you?

04

Why does the order of statements matter?

A bug: it runs, but the answer is wrong
Sign in to run this example in your browser.

Expected output

Total: 60