Welcome to Python Land · practice
Your First Python Instructions
In the previous lesson, you changed an instruction that was already waiting for you. This time, you’ll write new Python instructions yourself.
We will begin with one of Python’s most useful tools:
print("Hello")
This instruction asks Python to display the word Hello.
Taking a print instruction apart
Every character in print("Hello") has a purpose.
| Part | What it tells Python |
|---|---|
print | Use Python’s built-in printing |
( and ) | Give something to that function. |
"Hello" | Treat Hello as text. |
Hello | The text that should appear in the output. |
Python displays the text without its quotation marks:
Hello
The quotation marks belong to the code. They show Python where the text begins and ends.
Deep dive
The precise name for print("Hello") is a function call. print is the function, and "Hello" is an
Text between quotation marks is called a
Keep the structure, change the text
Once you know the shape of a print instruction, you can display almost any text you like:
print("Good morning")
print("Good evening")
The structure stays the same. Only the text between the quotation marks changes.
Python produces:
Good morning
Good evening
Notice that each print instruction starts on its own line. Python runs the first line, moves to the second, and continues downward.
Predict before you run
Read this short program from top to bottom:
What will this program print?
print("Ready")
print("Set")
print("Go!")Making a prediction before running code is a valuable habit. It gives you something specific to compare with the actual result.
Write two new instructions
The playground starts with one line:
print("Python is ready.")
Leave that line in place. Underneath it, write two more print instructions so the complete output becomes:
Python is ready.
I wrote my first instruction.
Then I wrote another one!
Use the starter line as a pattern. Each new line needs:
The lowercase name
printAn opening parenthesis
An opening quotation mark
The text you want to display
A closing quotation mark
A closing parenthesis
Type the new lines yourself if you can. Small details such as quotation marks and parentheses become familiar through use.
Press Run whenever you want to inspect the result. When all three output lines match, press Submit.
If a line doesn’t work
First, compare it with the starter line one character at a time. Check that:
printis lowercase.The text has a quotation mark at both ends.
The instruction has both parentheses.
The text itself has the same capital letters and punctuation as the target.
If the editor shows an error, you haven’t broken anything. The next lesson is devoted to understanding errors, and you can always use Reset to return to the starter code.
Monty can make the comparison with you. A useful request is:
Review my print instructions. Point out the first difference from the target, but let me correct it myself.
That kind of help is often more useful than receiving the finished answer. Monty remains included for free throughout this opening chapter.
Once your submission passes, take a moment to look at what you wrote. It may be a tiny program, but every instruction in it is yours.
Task
Keep the starter line and add two more print instructions. Your program must produce exactly:
Python is ready.
I wrote my first instruction.
Then I wrote another one!
Press Run to compare the result, then press Submit.