Lab: Mad Libs & a receipt printer

Practical

~75 min

Two small programs that force you to combine input(), type conversion, and f-string formatting. Type everything — no pasting.

1. Mad Libs (20 min)

A Mad Libs story asks for random words, then drops them into a story with (hopefully) funny results.

  1. Create week1/madlibs.py.
  2. Ask the user for four inputs: a name, a place in Nigeria, a food, and a number.
  3. Print a short story (3–4 lines) that uses all four, via f-strings.

Example run:

Give me a name: Emeka
A place in Nigeria: Onitsha
A food: jollof rice
A number: 47
One day, Emeka travelled to Onitsha with nothing but ₦200.
There, Emeka ate jollof rice 47 times in one afternoon.
The whole of Onitsha still talks about it today.

Requirements: all four inputs must appear in the output; the number must be used as a number at least once (e.g. print 47 times where 47 came through int() — try times + 1 somewhere to prove it converts).

2. Receipt printer (35 min)

You are building the print-out for a POS at Mama Nkechi Provisions, a shop in Surulere, Lagos.

  1. Create week1/receipt.py.
  2. Hard-code three items as variables (no input needed for this part): item name, quantity, unit price. Example data: Indomie carton ×2 @ ₦7,500; Peak milk tin ×6 @ ₦850; Golden Penny semovita ×1 @ ₦4,200.
  3. Compute a line total for each item and a grand total.
  4. Print a receipt with aligned columns using f-string width specifiers. {name:<20} pads text to 20 characters (left-aligned); {amount:>10,.2f} right-aligns a number in 10 characters with commas.

Target output (yours can differ slightly, but columns must line up):

MAMA NKECHI PROVISIONS
------------------------------------
Indomie carton    x2      15,000.00
Peak milk tin     x6       5,100.00
Semovita          x1       4,200.00
------------------------------------
TOTAL                 ₦   24,300.00
  1. Stretch (optional, 10 min): ask the user for the quantity of one item with input() + int() so the receipt changes per run.

Deliverable

Submit a link to a folder containing madlibs.py, receipt.py, and a screenshot of one full run of each from the terminal. In your notes: which f-string format specifier you found trickiest and what it does.

Reviewer checks: Mad Libs takes 4 inputs and uses the number as an int; receipt totals are computed (not hard-coded final numbers); columns align using format specifiers, not manual spaces; grand total is correct for the data shown; code was clearly typed/understood — student can explain any line if asked.

Sign in to submit your work.