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
2

Typing to the shell

Computing 7: Unit 7.1, pp. 8–43
GoalType single commands into the Python shell, use print and calculations, and explain why Python is case sensitive.
New words
Python shell · the window where you type one command at a time and Python answers at once (interactive mode)print statement · a Python command that shows text or a value on the screencase sensitive · able to tell capital letters from small lettersinterpreter · the part of Python that translates your commands for the computer, one line at a time
Explanation

When you open IDLE you see the Python shell. The symbol >>> is the prompt and it waits for you to type a command. This is called interactive mode. When you press Enter, the interpreter translates the line and Python carries it out at once. The command print("Hello") shows the text between the quotation marks, but a calculation such as 7 * 6 shows its answer without print. The symbol * means multiply and / means divide. Python is case sensitive: print is a command, but Print is not. Lines typed in the shell are not saved.

You type at >>>The shell shows
print("Hello")Hello
(4 + 6) * 330
12 / 43.0
2 + 3 * 414
Worked examples
You type at >>>The shell shows
10 - 2 * 34
(10 - 2) * 324
50 - 8 - 240
Brackets change the order of a calculation. The first two commands use the same numbers but give different answers, because Python works out the brackets first. In the third command both signs are minus, so Python works from left to right: 50 - 8 is 42, and 42 - 2 is 40.
Python
1Print("Good morning")
Output
NameError: name 'Print' is not defined
A capital letter in the command name is a mistake. Python does not know the word Print, so it reports a NameError.
Python
1print("Hello"
Output
SyntaxError: '(' was never closed
Nodira forgets to close a bracket. Python cannot read the line, so it reports a syntax error. Always count your opening and closing brackets.
Class activity

Be the interpreter (no computer): write these four lines on four slips of paper: print("Hi") · Print("Hi") · 6 * 7 · print("Hi). Mix the slips and pick one at a time. Your partner is the Python shell and must answer: what appears, or which mistake there is. Then swap roles and write four new slips with your own commands. Keep a score: one point for each correct answer. If you have a computer or tablet, type the slips into IDLE with an adult and check your answers.

Practice
1
Fill in the shell’s answers (the question marks).
You type at >>>The shell shows
print("Moon")?
8 * 5?
(2 + 4) * 5?
100 / 8?
2
This program shows Hello and then stops with an error. Why does line 1 work but line 2 does not? How do you fix line 2?
Python
1print("Hello")
2Print("Welcome")
Output
Hello
NameError: name 'Print' is not defined
3
Write the two commands you would type in the shell: one that shows the words Good luck! and one that takes 15 away from 90 and then divides the answer by 5.
4
Why is it correct to write a capital H in print("Hello"), but wrong to write a capital P in Print?