AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Typing your first code

Week 1 · Unit 7.1: Block it out · 3 lessons
1

Two ways to program

Computing 7: Unit 7.1, pp. 8–43
GoalCompare block-based Scratch with text-based Python and say what stays the same.
New words
block-based language · a language in which you build a program by dragging blocks togethertext-based language · a language in which you build a program by typing commandssyntax · the exact rules for how the commands of a language must be writtenIDLE · the program in which Python programs are typed, saved and run
Explanation

Scratch is a block-based language, where you drag blocks and snap them together like bricks. Python is a text-based language, where you type every command yourself. Python has strict syntax rules, so one missing bracket or quotation mark can stop a program. Python programs are written and run in a program called IDLE. Both kinds of language use the same ideas: a sequence of steps, input and output. Input is data going into the computer and output is what the computer shows. This is why someone who can use Scratch can learn Python.

JobScratch blockPython line
show a messagesay [Welcome!]print("Welcome!")
ask a questionask [Your name?] and waitname = input("Your name? ")
do steps in orderblocks stacked under each otherlines typed under each other
Worked examples
whenclickedsayWelcome to the zoo!for2seconds
Here is a small Scratch program. It shows a message in a speech bubble for two seconds.
Python
1print("Welcome to the zoo!")
Output
Welcome to the zoo!
This Python program does the same job. The word print is a command and the text goes between quotation marks and brackets. Python writes the message on the screen instead of in a bubble.
IdeaScratchPython
how you builddrag and droptype the code
syntax rulesthe blocks only fit together the right wayyou must write every word and symbol correctly
sequence, input, outputyesyes
good forlearning the ideasbigger and more advanced programs
Mia and Leo compare the two languages. Notice that Scratch cannot have a spelling mistake in a block, but Python can.
Class activity

Human interpreter (no computer): your partner writes three lines on paper, for example print("Hello"), print("I am Leo") and print("Goodbye"). You are the computer. Read the lines one at a time and say out loud what appears on the screen. Now the partner makes one spelling mistake on purpose, such as pront. You must say ‘error’ and stop, because Python does not know the word pront. Then play again with picture cards instead: the partner lays out cards that say ‘say Hello’, ‘say Goodbye’ in a row. Which way was easier to get wrong? If you have a computer or tablet, look at a Scratch program and a Python program side by side with an adult.

Practice
1
Give two things that stay the same and two things that change when a program moves from Scratch to Python.
2
What will the screen show when this program runs? Write the lines in order.
Python
1print("Pens")
2print("Pencils")
3print("Rulers")
3
Python shows this message and does not run the program. What mistake did the programmer make?
Python
1print("Open at nine)
Output
SyntaxError: unterminated string literal (detected at line 1)
4
Write this Scratch program in Python. Python does not wait two seconds, so ignore the timing.
whenclickedsayReady?for2secondssayGo!for2seconds