Free lesson · Module 1, lesson 2 of 8

How a computer follows instructions

Describe input, processing, output and memory with a vending machine, and trace three instructions that store and change a value in a labelled box.

The video for this lesson is being prepared

About 9 minutes, narrated in English, Hindi and Odia. The notes and the quiz below are open now.

Lesson notes

Input, processing, output

  • Input: what you give the machine (coins and the button; numbers you type; the amount and your UPI PIN)
  • Processing: the work done inside, which you cannot see (checking the money; adding; the bank checking the PIN and balance)
  • Output: what comes back to you (the snack and change; the answer on screen; the payment message)
  • To sort an item, ask: who gives it, and where does it go? Typing a PIN is input; checking it is processing

Memory: labelled boxes

  • Memory is a shelf of labelled boxes, like the jars in a kirana shop
  • Each box has a name and holds one value at a time
  • An instruction can put a value in, read it, or replace it
  • The processor follows one instruction at a time, in order
  • Python preview (next lessons): apples = 5 puts 5 in the box named apples

Tracing instructions

  • Put 5 in the box named apples, Add 3 to apples, Show apples shows 8 (not apples: Show gives the value inside the box, not its label)
  • Put 100 in the box named wallet, Put 40 in wallet, Add 10 to wallet, Show wallet shows 50
  • Practice: Put 200 in the box named balance, Put 75 in balance, Add 25 to balance, Show balance shows 100

The trace table

  • One column for each box, one row for each instruction
  • Put: write the new value; the old one is gone
  • Add: latest value plus the number
  • Show: read the newest value in the column

The trap

  • Wrong: a new value piles up on what is in the box (Put 100, then Put 40 gives 140)
  • Right: putting a value in a box replaces what was there (wallet holds 40); only Add combines values

Try it

  • On paper, trace: Put 60 in the box named marks, Add 15 to marks, Put 90 in marks, Show marks (answer: 90)

Lesson quiz

Checked in your browser. Nothing is sent or saved.

5 questions

Question 1 · easy

Why do we write programs in a programming language like Python instead of talking to the processor directly?

Question 2 · easy

What does this program print?

print("Ravi scored 50")

Question 3 · medium

What does the computer show after these instructions?

Put 12 in the box named runs
Add 6 to runs
Add 4 to runs
Show runs

Question 4 · medium

What does this program print?

print("Catch the bus")
print("Lock the door")
print("Pack the bag")

Question 5 · hard

Arjun saves these two lines in a file named bill.py on his laptop and runs it in Visual Studio Code. What appears in the terminal panel?

40 * 3
print("Bill is ready")

What a program is: a recipe for a computerNext: Meet Python and run your first line