Welcome to the first Cuppa and Code! Kettle on? Good. By the time your cuppa has cooled enough to drink, you will have written and run your first program, and you will know what a program actually is!

You will need: a Google account (we will use Colab, so there is nothing to install), a hot drink (any hot drink counts), and no experience at all.

homepage

So, what is a program?

A program is a list of instructions that a computer follows, in order.

Think of a recipe, but the cook is the most literal person you have ever met. They do exactly what the recipe says, in exactly the order it says it, and they never guess what you meant.

Here is a tiny "program" for making tea:

  1. Boil the water
  2. Put a teabag in the mug
  3. Pour the water into the mug
  4. Wait a few minutes
  5. Take the teabag out
  6. Add milk

Now imagine step 4 came before step 3. If you gave the incorrect instructions to a person, they would shrug and fix it. Give them to a computer, and it would do it in the order you wrote it because it has no idea what a good cup of tea looks like. (Whether milk goes in first is a separate debate that I will leave for the comments!)

Let's write one

Open the notebook using the Colab button above. Each box with a grey outline is a code cell. Click one, then press the play button on its left (or press Shift+Enter) to run it.

Each step in the notebook follows the same pattern: predict what will happen, run it, then modify it by changing something. Guessing first is what makes the idea stick, so try not to skip it.

Step 1: Your first program

print("Hello, world!") 

Predict what appears, then run it. print is an instruction that tells Python to show something on the screen. The quote marks tell Python "this is text, show it exactly as written".

Step 2: Order matters

print("Kettle on") print("Teabag in mug") print("Pour the water") 

Predict the order of the output, then run it. Now swap two of the lines and run it again. Python follows your new order without question.

Step 3: Restart and Run All

Notebooks let you run cells in any order, which is handy but can trick you. A notebook remembers things between cells, so if you run cells out of order, it can behave in ways that look like magic (or like a bug). The notebook has a short experiment that shows this, and ends with a habit that will save you hours:

Runtime > Restart session and run all

Whenever something acts strangely, do that first. It clears the notebook's memory and runs everything from the top, in order.

Myths worth busting early

  • "The computer understands what I meant." It only understands what you wrote. Fast and literal, never clever.
  • "Experts don't get errors." Everyone gets them, constantly. They are part of the job, and learning to read them is the real skill. That is the whole of the next post.

Tea break challenge

Write a program that prints the steps for making your perfect cuppa. At least five steps. Then swap two lines and see how silly the result gets.

There is a space for it at the end of the notebook. Post your finished program in the comments, and tell me: When you make a cuppa, milk first or milk last?

What you learned

  • A program is a list of instructions, run in order
  • print shows text on the screen
  • Quote marks mean "this is text"
  • Computers do exactly what you say, not what you mean
  • When a notebook acts strangely, restart and run all

Next time

In Cuppa and Code #2, red text appears on your screen and we will learn why that is good news. See you at the next brew!