CSC 1001 — Lab 5: The Ticket Price Problem
Intro
This is a lighter lab for midterm week. You'll trace a short piece of code on your own, then work individually through one problem from requirements to working code, and finish by comparing your work with a small group. No new syntax is introduced this week — everything here reuses conditionals and Boolean logic from the last few weeks.
| Section | Mode | What You'll Do |
|---|---|---|
| Understand | Individual | Trace a function that uses multiple if / elif / else branches and predict its output for several calls. |
| Do | Individual | Work the Ticket Price problem end-to-end: requirements → subtasks → pseudocode → assemble the code. |
| Communicate | Groups of 3–4 | Compare your requirements, subtasks, pseudocode, and code order with your group and agree on one final version. |
Submit: your Lab 5 Worksheet. There is no code and no notebook to submit this week.
Understand (Individual)
Trace the code
Below is a function with two separate decision structures. Without running it, trace through it by hand for each call listed, and record your trace on your Lab 5 Worksheet.
age: int = 0
hasPass: bool = True
if age < 5:
price = 0
elif age < 13:
price = 6
elif age >= 65:
price = 7
else:
price = 10
if hasPass and price > 0:
price = price - 3
elif hasPass:
price = price
print(price)
Calls to trace:
- age is 8, has pass
- age is 70, no pass
- age is 4, has pass
Do (Individual)
The Ticket Price problem
Read the scenario below, then work through each step in order. Don't skip to the code — the requirements and pseudocode are what make the code make sense.
Scenario: Sunset Cinema Ticket Price
Sunset Cinema wants a simple tool that calculates the price of one ticket.
- The standard adult ticket is $12.
- Children under age 13 pay $8.
- Seniors age 65 and older pay $9.
- Every Tuesday, the cinema takes $3 off the ticket price to bring in more customers — but a ticket should never cost less than $5.
- Customers with a valid student ID get an additional $2 off, applied after the Tuesday discount. This discount also cannot bring the price below $5.
The program should take a customer's age, whether today is Tuesday, and whether they have a student ID, and output the final ticket price.
Step 1 — Requirements
List the inputs, the output, and the business rules in your own words on your Lab 5 Worksheet.
Step 2 — Subtasks
Break the problem into a short sequence of steps (not code yet — just the order of operations). Record your steps on your worksheet.
Step 3 — Pseudocode
Write pseudocode for the full problem on your worksheet. Use IF / ELIF / ELSE and be explicit about the $5 floor on both discounts.
Step 4 — Construct the code
Below are lines of a Python solution, shuffled and labeled. Two of the lines are wrong on purpose. On your worksheet, write the letters, in order, for only the lines that belong in a correct solution (skip the incorrect ones), and identify what's wrong with the two incorrect lines.
age: int = 5
isTuesday: bool = True
hasStudentId: bool = True
A if age < 13:
B elif age > 65:
C elif age >= 65:
D price: int = 8
E price: int = 9
F else:
G price: int = 12
H if isTuesday:
I price: int = price + 3
J price: int = price - 3
K if price < 5:
L price: int = 5
M if hasStudentId:
N price: int = price - 2
O if price < 5:
P price: int = 5
Q print(price)
Communicate (Groups of 3–4)
Compare and agree
Form a group. Each person should have already completed the Do section individually. Go through the comparison below together.
| Compare | Discuss |
|---|---|
| Requirements | Did everyone list the same inputs and output? If someone's rules were worded differently, does it still mean the same thing? |
| Subtasks | Whose sequence of steps was clearest? Is there a step someone missed, or an extra step someone added that wasn't needed? |
| Pseudocode | Does everyone's pseudocode enforce the $5 floor in the same place? What happens if the floor check is left out? |
| Code order | Did everyone pick the same two wrong lines? If someone ordered the correct lines differently, would their program still work? |
As a group, agree on one final version and record it on your Lab 5 Worksheet (final pseudocode, final code order, and names in your group).