1. Hello, Bit
Morag has bought a laptop for the chip van. Bit has claimed the keyboard as a perch. Morag's plan: learn to program, so the van can take orders without her shouting them across the pier.
You are going to learn with her. No reading about swimming: you get in the water straight away. Every grey box on this page is real Python. Press Run and it runs.
Who's who: Morag is a Highland cow who runs a chip van on the pier. Bit is the seagull who lives on its roof and understands exactly two things: chip, and no chip.
Your first program
A program is a list of instructions. Here is one with a single instruction. Run it.
print("Hello, Bit")
print tells the computer to display something. The thing to display goes inside the brackets. Because it is text, it goes inside quotes. Change the words and run it again. Go on. Nobody is watching.
More than one line
Instructions are carried out in order, from the top down.
print("One chip")
print("Two chips")
print("No chips. Bit was here.")
Make the program display exactly this: Welcome to Morag's Chips
Use print, brackets and quotes. Spelling and capital letters must match exactly.
Display the menu on three lines: Fish supper, then Haggis supper, then Chips.
You need three print instructions, one under the other.
When it goes wrong
Computers are fussy. Miss out one quote or one bracket and Python refuses to run the program at all. That is called a syntax error, and every programmer alive makes several a day. The skill is not avoiding them. It is reading the message, finding the line, and fixing it.
Morag typed these with hooves. Each line has one mistake. Fix them so the program displays Bit wants a chip and then Bit is always hungry.
Quotes come in pairs: one before the text and one after it.
For National 5In exam questions, code is written in a reference language. Its instruction for displaying something is SEND "Hello" TO DISPLAY. Python's print("Hello") does the same job. You can answer exam questions in Python.
Next: lesson 2, where the computer starts remembering things.