Your first program
In the last lesson you printed text to the screen with print. Now let’s break that command down into its parts.
The anatomy of print
Section titled “The anatomy of print”print("Hello!")There are three parts:
print— the name of the command: “display this”()— the parentheses: whatever gets printed goes inside them"Hello!"— the text, inside quotes. The quotes tell the computer: “this isn’t a command, it’s just text.”
All three matter. What happens if you forget one? Let’s find out. 🙂
An error is your friend
Section titled “An error is your friend”In the code below, the closing quote is left out on purpose. Run it and see what happens:
Inputs (for input())
One value per line — read in order by input().
See the red text? That’s an error. The computer is saying “I didn’t understand this line” — and it shows you which line has the problem.
Remember this: an error isn’t a punishment, it’s a hint. Even the most experienced programmers see errors every day. The only difference is that they’ve learned to read an error and fix it. Now you will too — add a " after the ! in the code above and run it again.
Lines run in order
Section titled “Lines run in order”A program can have as many print lines as you want — the computer runs them top to bottom:
Inputs (for input())
One value per line — read in order by input().
Missions
Section titled “Missions”Introduce yourself
+10 XP ✓ CompletedIntroduce yourself with three print commands: your name, your age, your city. (Lines starting with # are comments — the computer ignores them; they’re notes for you.)
Inputs (for input())
One value per line — read in order by input().
Fix the error
+10 XP ✓ CompletedThis program is broken — run it and you’ll see an error. Read the error, find the cause, fix it, and run it.
Inputs (for input())
One value per line — read in order by input().
Print it exactly
+10 XP ✓ CompletedWrite a program that prints exactly this sentence to the screen: I am a programmer!
Inputs (for input())
One value per line — read in order by input().
Next module: the real conversation with Python begins — you’ll join text together, do math, and teach your program to talk. Continue →