🐍 Python for Everyone

← Back to the quiz

Chapter 1 Exercises 15 min, hands-on

Exercises: Your First Python Program

These exercises use only what Chapter 1 covered: print(), variables, basic types (string, int, float), input(), and joining text with + / str().

How to run these You'll need Python 3 installed (check with python3 --version). Download starter.py below, then run it from a terminal with python3 starter.py.

The four tasks

1 Say hello, your way

Open starter.py. Find # TODO 1 and print a greeting of your choice using print().

2 Store your details

Find # TODO 2. Create three variables: city (a string), favorite_number (an int), and temperature_today (a float). Print all three.

3 Ask, don't tell

Find # TODO 3. Use input() to ask the user for their favorite color, store it in a variable, then print a sentence that includes their answer.

4 Fix the type error

Find # TODO 4. There's a line that tries to join a string with a number directly and will crash with a TypeError. Fix it using str(), the way Chapter 1's "Go Deeper" box explained.

Starter code, at a glance

starter.py
"""
Chapter 1 Exercises: Your First Python Program
"""

# TODO 1: Print a greeting of your choice.

# TODO 2: Create three variables — city (string), favorite_number (int),
# and temperature_today (float) — then print all three.

# TODO 3: Ask the user for their favorite color with input(), store it,
# then print a sentence that includes their answer.

# TODO 4: Fix the TypeError below using str().
visits = 5
print("You've visited this page " + visits + " times.")
Checking your work There's no automated grader for this exercise — that's intentional at this stage. Compare your output against solution.py to see one correct way of doing it. Your wording and variable choices don't need to match exactly — the goal is that your program runs without errors and does what each TODO asks.
← Back to Quiz Practice Bank →