Python 3.03: Math Expressions HW
Python 3.03 Math Expressions
This homework is reconstructed from the last preserved OCS version in PR #1592. It includes both Popcorn Hacks and the Recovery Center Cost Report homework.
Popcorn Hack 1: Basic Arithmetic Operators
Use the provided variables with addition, subtraction, multiplication, and division instead of hardcoding the results.
Code Runner Challenge
Popcorn Hack - Basic Arithmetic Operators
View IPYNB Source
# CODE_RUNNER: Popcorn Hack - Basic Arithmetic Operators
base_value = 100
step_value = 10
extra_value = 25
# Add all three values using the variables.
addition = base_value + step_value + extra_value
# Subtract B from A.
subtraction = base_value - step_value
# Multiply B and C.
multiplication = step_value * extra_value
# Divide A by B.
division = base_value / step_value
print("Total:", addition)
print("Difference:", subtraction)
print("Product:", multiplication)
print("Division:", division)
Expected results: Total 135, Difference 90, Product 250, Division 10.0.
Popcorn Hack 2: Poway Recovery Center Booking Math
The recovered PR’s Python task uses multiplication, subtraction, and division to calculate occupied capacity, remaining capacity, and users per room.
Code Runner Challenge
Python Version of Popcorn Hack 2
View IPYNB Source
# CODE_RUNNER: Python Version of Popcorn Hack 2
# Starting values for the Poway Recovery Center booking system.
total_monthly_capacity = 100
spots_requested_per_group = 4
sessions_booked = 3
# Multiplication finds the total spots used by the group across all sessions.
total_spots_taken = spots_requested_per_group * sessions_booked
# Subtraction finds how much capacity remains.
remaining_capacity = total_monthly_capacity - total_spots_taken
# Division splits the remaining capacity evenly between two rooms.
users_per_room = remaining_capacity / 2
print("Total Spots Taken:", total_spots_taken)
print("Remaining Capacity:", remaining_capacity)
print("Users per Room:", users_per_room)
Expected results: Total Spots Taken 12, Remaining Capacity 88, Users per Room 44.0.
Homework Hack: Recovery Center Cost Report
Calculate the weekly cost, monthly cost, monthly total with the one-time enrollment fee, and average daily monthly cost.
Code Runner Challenge
3.03 HOMEWORK - Recovery Center Cost Report
View IPYNB Source
# CODE_RUNNER: 3.03 HOMEWORK - Recovery Center Cost Report
session_cost = 35
weekly_sessions = 3
month_weeks = 4
enrollment_fee = 75
# Weekly cost is the session price times the number of weekly sessions.
weekly_cost = session_cost * weekly_sessions
# Monthly cost scales the weekly amount by four weeks.
monthly_cost = weekly_cost * month_weeks
# Add the one-time enrollment fee to the monthly session cost.
first_month_total = monthly_cost + enrollment_fee
# Divide the monthly session cost by 30 days for the requested daily average.
daily_average = monthly_cost / 30
print("Weekly Cost:", weekly_cost)
print("Monthly Cost:", monthly_cost)
print("Total Cost with Fee:", first_month_total)
print("Average Daily Cost:", daily_average)
Homework Results
Weekly Cost: 105
Monthly Cost: 420
Total Cost with Fee: 495
Average Daily Cost: 14.0