← Back to course
Code Crew G6+ / Week 01 / Monday
1/6
Week 01 Β· Hello, Mission Control

Monday

Mission Control comes online
// Your first real Python programs
⏱ about 30 min

Monday: Mission Control comes online

Mission Control is quiet until Rocket hurries in with a laptop and a big grin. "I have an idea!" he says. "We are going to build our own tools for the crew, and we start today."

Raven sets down her notebook and studies the screen. A plain white window shows three small arrows and a blinking cursor. "What do you notice?" she asks. "Those arrows look like they are waiting for something."

Nova hovers over the desk, her cyan lights pulsing. "Would you like a hint?" she asks. "That window is listening. Type one instruction and it will answer right away."

Rocket is ready to type ten things at once. Raven laughs and suggests they start with one small line and watch what happens.

Python and IDLE

Python is a programming language: a precise way to give a computer instructions. Programmers all over the world use it, and it is the language you will use for this whole course.

IDLE is a small program that comes with Python. When it opens, you see the shell. The three arrows, >>>, are called the prompt. The prompt means Python is ready for one instruction.

Type an instruction after the prompt and press Enter. Python runs it and shows the answer on the next line. Then a new prompt appears, ready for the next one.

>>> 2 + 3
5
>>> 7 * 6
42
>>> 10 / 4
2.5
>>> print("Mission Control online")
Mission Control online

In Python, * means multiply and / means divide. Dividing with / always gives a number with a decimal point, even when it divides evenly.

The last line uses print, which shows whatever is inside its round brackets. The words are inside quote marks, so Python treats them as text and shows them exactly.

READ THE SHELL
  • Read the question.
  • Tap your answer.
What do the three arrows >>> in the shell mean?
Which symbol multiplies two numbers in Python?
Predict: what does the shell show after >>> 9 * 3 ?
WHY THIS EXERCISEThe shell works out the math and shows the answer on the next line.
Predict: what does the shell show after >>> 7 / 2 ?
WHY THIS EXERCISEThe / sign always gives a decimal answer, so 7 / 2 is 3.5, not 3.
For a grown-up
Before this session, please install Python 3 (version 3.10 or newer) from python.org, the official home of Python. It is free, and IDLE comes with it.
On Windows, run the installer with its default choices. IDLE then appears in the Start menu with the Python 3 programs.
On a Mac, run the installer. IDLE is in the Python 3 folder inside the Applications folder.
On Linux, Python 3 is often already there, but IDLE may be a separate package in your software manager.
Help your learner make one folder called mission, for example inside Documents. Every program in this course is saved in that folder.
The course programs never use the internet, never install anything and never ask for personal information.
At your computer
1. Open IDLE. The shell window appears with the >>> prompt.
2. Type 2 + 3 after the prompt and press Enter. You should see 5.
3. Type 7 * 6 and press Enter. Check that you see 42.
4. Type 9 * 3 and press Enter. Was your prediction right?
5. Type print("Mission Control online") and press Enter.
6. Make up three math questions of your own. Predict each answer before you press Enter.

Which math happens first?

Python follows the same order as math class. It multiplies and divides first, then adds and subtracts, working left to right.

Round brackets change the order. Whatever is inside brackets is worked out before anything else.

>>> 2 + 3 * 4
14
>>> (2 + 3) * 4
20
>>> 10 - 4 / 2
8.0
>>> 8 / 2
4.0
ORDER OF OPERATIONS
  • Read the question.
  • Tap your answer.
Why does 2 + 3 * 4 give 14 and not 20?
Which line gives 20?
Why does 8 / 2 show 4.0 instead of 4?
Predict: >>> 6 + 4 / 2 shows ____
Predict: >>> (6 + 4) / 2 shows ____
Predict: >>> 3 * 3 - 1 shows ____
Shell lineIs the answer right?
>>> 1 + 2 * 3 shows 7?
>>> (1 + 2) * 3 shows 7?
>>> 9 / 3 shows 3.0?
>>> 5 * 2 + 1 shows 15?
WHY THIS EXERCISEBrackets make (1 + 2) * 3 equal 9, not 7. Also, 5 * 2 + 1 is 11, not 15.

You just talked to Python for the first time, and it answered. Tomorrow you will use print to make Python say exactly what you want.