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.
No reading — just build. Keep 2.3 (MOD) and 2.4 (int / float) open in a tab; you’ll want them.
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.
Write a small calculator program in Python. It must:
□ 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.
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.
# 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))
// 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.)
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.
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().
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.
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:
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.
□ 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?
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.