Homework 5: Mad Libs Calculator
File to submit: `mad_libs.ipynb + docx containing (trace table + reflection sentence (see Deliverables))
Overview
You will write a short Python program that collects a few pieces of information from the user, does a little arithmetic, and then uses a nested conditional to decide which "story" to print. This assignment pulls together everything you've worked on so far: variables, arithmetic expressions, conditionals, nested conditionals, and breaking a problem into logical steps.
You are not being graded on how elegant or clean your code is. You're being graded on whether the logic is correct and whether you can explain how it behaves — including on inputs that break it.
Requirements
Write a program called mad_libs.py that does the following, in order:
1. Collect input
Ask the user for:
- name (a string)
- favorite animal (a string)
- age (a number)
2. Calculate a "Life Score"
Use this exact formula:
life_score: float = (age * 7) + len(name)
age * 7— a simple arithmetic scaling of agelen(name)— the number of letters in their name, added on top
3. Handle bad input first
Before computing tiers, check whether age is negative.
- If
age < 0: print an error message (e.g.,"Age can't be negative — try again.") and skip the rest of the program (don't calculate a tier). - Otherwise, continue to step 4.
4. Determine the tier (nested conditional required)
Using life_score, assign the user to one of the following tiers:
| Tier | Condition |
|---|---|
| Rookie | life_score < 50 |
| Solid | 50 <= life_score < 100 |
| Legendary | life_score >= 100 |
Nested check: If the tier is Legendary, add one more check inside that branch:
- If
life_score >= 150: the tier name becomes "Suspiciously Legendary" (e.g., they lied about their age) - Otherwise, it stays "Legendary"
This inner check is the required nested conditional — it only makes sense to check it after we already know the person is in the Legendary branch.
5. Print the result
Print a Mad-Libs-style sentence using all the variables. For example:
Behold! NAME, protector of the ANIMAL kingdom, has achieved a Life Score of SCORE
and has been crowned... TIER!
(Exact wording is up to you — the sentence just needs to include the name, animal, score, and tier.)
Deliverables
Submit three things:
-
mad_libs.py— your working script. -
Docx file containing:
-
Trace table — hand-trace your program's execution for the two inputs below. For each input, track the value of every variable (
name,animal,age,life_score,tier) at each step of the program, and write down the final printed output.Input Set name animal age A "Sam""otter"12B "Alexandria""falcon"20 -
One written sentence explaining why the "Suspiciously Legendary" check needs to be nested inside the Legendary branch, rather than written as a separate, flat
elifalongside Rookie/Solid/Legendary. 2. One written sentence explaining why the "Suspiciously Legendary" check needs to be nested inside the Legendary branch, rather than written as a separate, flatelifalongside Rookie/Solid/Legendary.
-
Grading Focus
You will primarily be assessed on:
- Whether your conditional logic matches the tiers/thresholds above (including the nested check)
- Whether your trace table shows correct values at each step — this is where we check your understanding, independent of your code-writing fluency
- Whether your reflection sentence correctly explains the nesting logic
Style and "cleanliness" of code are not graded here.