Values and Variables · capstone
Capstone project: Project: Plan a Group Outing
You now know how to name values, update
You will build a budget summary for a group outing. The starting information is already in the editor so you can focus on turning it into useful results.
Starting information
Your program begins with four variables:
activity = "museum visit"
people = 3
price_per_person = 12
snack_budget = 15
Do not change those values until after your project passes. They give you a known result to check.
Part 1: Calculate the budget
Create two new variables:
ticket_totalshould multiplypeoplebyprice_per_person.total_budgetshould addticket_totalandsnack_budget.
Work out the expected values before you run the program:
Tickets cost
3 * 12, which is36.Adding the snack budget gives
36 + 15, which is51.
Writing down an expected result is a valuable check. If Python produces something else, you know there is a difference to investigate.
Part 2: Print the summary
Use five print instructions to produce exactly:
GROUP OUTING
Activity: museum visit
People: 3
Tickets: $36
Total budget: $51
The first line can be an ordinary
Build it in checkpoints
You do not need to write the complete program before running it.
Calculate
ticket_totaland print it temporarily. Check for36.Calculate
total_budgetand print it temporarily. Check for51.Remove those temporary checks.
Add the five required output lines one at a time.
Compare the final output carefully with the target.
Small checkpoints make it easier to locate a mistake. They are not just for beginners. Experienced programmers use them too.
Review your program
Before submitting, check that:
all six variable names are spelled consistently;
both calculated variables use
, not quoted answers; each f-string begins with
f;every opening brace has a closing brace;
the dollar signs are outside the braces;
the output has exactly five non-empty lines.
If your subscription includes Guided, a useful Monty request is:
Review my outing program against the requirements. Check the calculations first, then the output. Point out one issue at a time without rewriting the program.
The lesson instructions, Run button, and submission feedback are enough to complete the project independently too.
After it passes
Once you have a passing version, make the plan your own. Change the activity, number of people, price, or snack budget and press Run again. Watch the calculated totals and f-strings update from the new values.
To submit again, restore the four starting values listed above while keeping your calculations and print instructions. Reset restores the unfinished starter program, so use it only when you want to start the exercise again.
What you have learned
In this chapter, values stopped being isolated pieces of code. You learned to give them useful names, replace them, combine them in calculations, and present them inside clear messages.
Your outing program has a simple but important structure:
Store the starting information.
Calculate new information.
Present the result.
That structure appears in programs of every size. In the next chapter, your programs can start receiving information from the person using them.
Task
Complete the group outing program.
Calculate
ticket_totalaspeople * price_per_person.Calculate
total_budgetasticket_total + snack_budget.Print exactly:
GROUP OUTING
Activity: museum visit
People: 3
Tickets: $36
Total budget: $51
Use one print instruction per line. The heading can be an ordinary
Keep the four starting values unchanged until your submission passes.