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 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.
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
| Shell line | Is the answer right? |
|---|---|
| >>> 1 + 2 * 3 shows 7 | ? |
| >>> (1 + 2) * 3 shows 7 | ? |
| >>> 9 / 3 shows 3.0 | ? |
| >>> 5 * 2 + 1 shows 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.