Skip to Content
Skip to content
Course content

Written lab 01 — Set up Python and make a decision

New FCGS companion material · November 2026

Download the tested project from the first written lesson in this course. It is new material, not a recovered recording.

Written lab 01 — Set up Python and make a decision

What you will build

Run a small terminal program that greets a captain and decides whether a purchase is affordable.

Before you start

No programming experience. Install Python 3.12 and extract the companion project into a writable folder.

A terminal is the text window where you run Python; the Python interpreter executes the file. Your editor saves code but does not determine which interpreter the terminal uses. Check the interpreter version before debugging your program.

input returns text, even when the player types digits. Here we only ask for a name. strip removes surrounding whitespace; the fallback name handles an empty answer. coins and price are integer values, so comparing them does not require a conversion.

An if statement chooses one indented block. The test uses >= because exactly enough money is affordable. A variable name describes a value; the equals sign assigns that value, while == compares two values.

Run the checkpoint

  1. Check python --version or python3 --version; use 3.12 for the verified path.
  2. Run python checkpoints/01_setup.py from the extracted project root.
  3. Enter Ada when prompted. Run again with an empty name.
  4. Change coins to 4, save the file, and rerun. Then change it to 5 and rerun.
name = input('Captain name: ').strip() or 'New Captain'
coins = 100
price = 5
print(f'Welcome, {name}. You have {coins} coins.')
if coins >= price:
    print('You can afford one unit of silk.')
else:
    print('You need more coins.')

Expected result

With 100 coins, the program greets your captain and says one unit of silk is affordable. With 4 coins, it says you need more; 5 coins is affordable.

Your exercise

Add a capacity variable. Display a second decision that checks whether at least one cargo slot is available. Try capacities 0 and 1.

Compare your approach

Use capacity = 1, then if capacity >= 1: with an indented print. Keep this separate from the money check for now; a later transaction will require both conditions together.

Check your understanding

Why would coins = '100' be a mistake in this example?

Answer and explanation

That is text. Comparing it with the integer price raises TypeError. Keep quantities as numbers and convert input deliberately.

Rating
0 0

There are no comments for now.

to be the first to leave a comment.

Additional Resources
to access resources