Python Foundations Lesson 1 of 7

Your first Python program

35 min, 9 exercises

Learn

Your first line

print() shows what you put inside its brackets. Text goes inside quote marks, so Python knows it is text. Each print() shows one line. Press Run.

TryPredict the output

One line or two

What will this print?

exercise_1.py
print("Hi")
print("there")

TryChange it

Make it say your name

Make it say your name. Text goes inside quotes. Replace ??? with your name, keep the quotes.

Constraint

  • Keep print( ), and keep your text inside the quotes.
  • Replace ??? with your name.
exercise_2.py to run
print("Hello, ???")

Try

Your first error

Take the quotes off and run it. Python can't find anything called Hello, so it stops and tells you.

  • Goal: get a NameError
exercise_3.py to run
print("Hello")

TryFix the bug

Put the quotes back

Here is your line from before, with no quotes. Put them back.

Constraint

  • Put a quote mark on each side of Hello.
exercise_4.py to run
print(Hello)

Learn

The parts of a line

The parts of one line

  • printa function, does a job
  • ( )holds what to print
  • "Hello"a string, text
main.py to run
print("Hello")

Learn

Commas and notes

A comma prints two things with a space between. A line starting with # is a note Python skips, so it never shows up.

main.py to run
# this line is a note
print("Score", 10)

Look it upNameErrorPython cheatsheet

TryPredict the output

What the comma does

What will this print?

exercise_5.py
# a note for people
print("Level", 1)

Practice

Say hello

Make the program print exactly this one line:

Hello, Python!

Capital letters, comma and exclamation mark all count.

exercise_6.py to run
# Change the text inside the quotes
print("Hello")

Practice

Three lines

Print three lines, in this order, using three print() calls: Ready, then Set, then Go!

Constraint

  • Use three print() calls, one for each line.
exercise_7.py to run
print("Ready")

Break/fixFix the bug

The game will not start

This program should print two lines, but Python refuses to run any of it. Run it, read the error, then fix it.

exercise_8.py to run
print("Welcome to the game!)
print("Press start")

Your turn

A game's title screen

Write a program that prints this title screen, line for line. On the middle line, give print() the text and the numbers as separate values with commas, not as one string.

Output
SPACE DRIFT
Level 1 of 12
Press start

Constraint

  • On the middle line, give print() 1 and 12 as numbers, with commas between the values.

On your own. Hints open after your first check.

exercise_9.py to run
main.py to run
print("Hello")
Python 3.13

Code editor. Press Control or Command plus Enter to run the code. Tab indents; to move focus out of the editor, press Escape and then Tab.