Skip to content

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.

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. 🙂

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().

Output
 

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.

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().

Output
 
Mission

Introduce yourself

+10 XP

Introduce 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().

Output
 
Mission

Fix the error

+10 XP

This 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().

Output
 
Mission

Print it exactly

+10 XP

Write 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().

Output
 

Next module: the real conversation with Python begins — you’ll join text together, do math, and teach your program to talk. Continue →