Unit 2 · Programming 1 · Lesson 2.5 · Lab

Lab: Calculator Day

Everything from this week — variables, math, MOD, input, conversion — in one small program you write from scratch. And you start the habit the Create PT is built on.

Big Idea 3 — Algorithms & ProgrammingHands on keys

Before this lab

No reading — just build. Keep 2.3 (MOD) and 2.4 (int / float) open in a tab; you’ll want them.

1

Where We Are

People→ Bits→ Programs→ Internet→ Security→ Big Data→ Impact

First full Programs build. Four lessons of pieces; today they become a whole thing that takes a real person’s numbers and gives back a real answer.

2

The Brief

Write a small calculator program in Python. It must:

Requirements — every program

□ Open with a purpose sentence as a comment (section 4).

□ Ask the user for at least two inputs with clear prompts.

□ Convert them with int() or float() before any math.

□ Do the calculation using variables and an expression.

□ Print a clean result the user can actually read (a sentence, not a bare number).

You’ll choose two of the three programs in section 3. Test each with a partner before you call it done.

3

The Model, Then Your Two

Here is a complete one to copy the shape of — not the problem you’ll turn in, but the pattern all three share: prompt → convert → compute → print a sentence.

Python — tip splitter (the model)

# This program splits a bill with tip so that
# friends know exactly what each person owes.
bill = float(input("Bill total? "))
people = int(input("How many people? "))
tip = bill * 0.18
each = (bill + tip) / people
print("Each person owes $" + str(each))

AP Pseudocode — the same logic

// purpose stated up top
//
bill ← INPUT()
people ← INPUT()
tip ← bill * 0.18
each ← (bill + tip) / people
DISPLAY("Each owes " + each)

Hover or tap a line to light its twin. Note line 5’s str(each) — to join a number onto text with +, Python needs it turned back into text first. (An f-string does this more cleanly; that’s 2.7.)

Choose two to build

A · Age in days

Ask for the user’s age in years, then print roughly how many days they’ve been alive. One input, one multiplication, one clean sentence. Stretch: also ask for the current month and adjust.

B · Temperature converter

Ask for a temperature in Fahrenheit and print it in Celsius, using C = (F - 32) * 5 / 9. Watch your types — this one needs float(), not int().

C · Minutes to hours-and-minutes

Ask for a whole number of minutes and print it as H hours and M minutes. This is a // and % problem — MOD from 2.3 doing real work.

4

The Purpose Sentence — Start the Habit

Every file you write from now until May opens with one comment line: what the program does, and why. It feels trivial. It is literally the first thing the Create PT written response asks you for — so we train it from week one. Fill in the blanks and read it back:

This program so that
# your purpose sentence appears here

A good purpose sentence names an action and a reason. “This program does math” fails both. “This program converts Fahrenheit to Celsius so that a traveler can read a foreign forecast” nails both.

5

Before You Submit

Test it like a stranger will use it

□ Does it run with no red errors?

□ Did you convert every input before doing math? (The 2.4 gotcha.)

□ Is the output a readable sentence, not a bare number?

□ Did a partner run it and get a sensible answer?

□ Does the purpose sentence at the top actually match what it does?

6

Challenge Tier — If You Finish Early

Paint-cost estimator

Ask for a wall’s width and height in feet and the price of one gallon of paint. One gallon covers about 350 square feet. Compute the area, figure out how many whole gallons are needed (you can’t buy 1.4 gallons — MOD and // help here), and print the total cost. This one forces you to round up, which is a genuinely useful real-world twist.

7

Connections

Uses all of Week 1 — variables (2.2), expressions and MOD (2.3), input and conversion (2.4), wrapped in a purpose (2.1’s “what does this program do?”).
Builds the PT habit — the purpose sentence is Create PT written-response #1, trained now so it’s automatic in May.
Next in 2.6 — strings get interesting: slicing your name like the row of characters it secretly is.
Returns in 2.17 — Mini-Project 2 (Quiz Bot) is this same shape, scaled up, with decisions added. Everything you practice today, you reuse there.
← 2.4 Input and Output