Making Decisions · capstone
Capstone project: Project: Build a Recommendation Tool
You can now make a program choose among several paths using comparisons,
You choose the tool’s subject and recommendation text. It could suggest activities, books to read, ways to practice a hobby, meal ideas, study approaches, or another suitable topic.
The program’s structure stays consistent so you can test it and receive useful automated feedback.
Personalize five strings
Create non-empty
| Variable | Purpose |
|---|---|
tool_title | A title printed at the top of the report |
quick_choice | A recommendation for anyone with less than 20 minutes |
active_choice | A recommendation for an active preference with at least 45 minutes |
quiet_choice | A recommendation for a quiet preference with 20 minutes or more |
flexible_choice | A fallback for another preference with 20 minutes or more |
Make all four recommendation strings different. The values can match any subject you choose.
For an activity guide, you might use short values such as "Take a brisk walk" or "Read a chapter". Those are examples, not required answers.
Collect two answers
Ask for a preference and a number of available minutes. Clean the preference and convert the number. These input calls are already in the project’s Editor. While building the collect-and-clean checkpoint, add the two temporary print calls below, press Run, and answer each question in the
preference = input("Preference (active or quiet): ").strip().lower()
minutes = int(input("Minutes available: "))
print(f"Cleaned preference: {preference}")
print(f"Minutes as a number: {minutes}")
Try ACTIVE with spaces at both ends and 60 minutes. The temporary checks should show active and 60. Remove these two print calls when you add the final four-line report.
The project assumes the minutes answer is a whole number. You do not need to add try/except or a validation
Apply the rules in order
Choose recommendation with one elif/else chain. Use these rules in this exact order:
When
minutesis less than20, choosequick_choiceregardless of preference.Otherwise, when
preferenceis"active"andminutesis at least45, chooseactive_choice.Otherwise, when
preferenceis"quiet", choosequiet_choice.In every other case, choose
flexible_choice.
The order is part of the design. The quick rule comes first because it overrides the preference when little time is available.
Print a four-line report
After the decision, print this structure with the actual values:
[tool title]
Preference: [cleaned preference]
Minutes: [number]
Recommendation: [chosen recommendation]
Do not print the square brackets. They show where your values belong.
Build in checkpoints
1. Personalize
Write the title and four different recommendation strings. Print them temporarily if you want to check spelling.
2. Collect and clean
Add the two input calls. Run the program with extra spaces and uppercase letters in the preference to confirm that the stored
3. Choose
Build the branches in the required order. recommendation in every branch.
4. Present
Print the four-line report. Remove temporary checks that are not part of the report.
Test every path
Run at least these four cases before submitting:
| Preference | Minutes | Expected choice variable |
|---|---|---|
active | 10 | quick_choice |
active | 60 | active_choice |
quiet | 30 | quiet_choice |
| another word | 30 | flexible_choice |
Also test the boundary values 20 and 45. Saying each rule aloud before running it can help you predict the result.
Before you submit
Check that:
the title and all four choices are non-empty strings;
the four recommendation strings are different;
preferenceis stripped and lowercased;minutesis converted withint();the quick branch comes first;
the active branch uses
andand includes the45boundary;every branch assigns one of your personalized choice variables;
the report contains exactly the four required non-empty lines after the input prompts.
If your plan includes Guided, you can ask Monty:
Review my recommendation tool one rule at a time. Check the order and boundary values without rewriting the program for me.
After it passes
Try different recommendation text while keeping the decision rules intact. Then trace one of the four test cases by hand and follow how Python skips
You have moved from programs that always follow one path to programs that respond to their current data. The next chapter introduces
Task
Build and personalize an interactive recommendation tool.
Write a non-empty
tool_titleand four different recommendation. Clean
preferencewith.strip().lower()and convertminuteswithint().Choose
quick_choicebelow 20 minutes.Choose
active_choicefor an active preference with at least 45 minutes.Choose
quiet_choicefor a quiet preference when the quick rule did not match.Use
flexible_choicein every other case.Print the required four-line report.
Submit uses private input with spaces and uppercase letters. Enter a whole number when testing the program yourself.