Python 3.03 - Math Expressions HW
Python 3.03 Math Expressions
This homework covers both Popcorn Hacks and a Recovery Center Cost Report, all using variables and arithmetic operators instead of hardcoded answers.
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
value_a = 100
value_b = 10
value_c = 25
addition = value_a + value_b + value_c
subtraction = value_a - value_b
multiplication = value_b * value_c
division = value_a / value_b
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
Multiplication, subtraction, and division give the total spots taken, the remaining capacity, and the users per room at the Poway Recovery Center.
Code Runner Challenge
Python Version of Poway Recovery Center Booking Math
View IPYNB Source
# CODE_RUNNER: Python Version of Poway Recovery Center Booking Math
total_monthly_capacity = 100
spots_requested_per_group = 4
sessions_booked = 3
# Multiplication: spots taken by all booked sessions.
total_spots_taken = spots_requested_per_group * sessions_booked
# Subtraction: capacity still available.
remaining_capacity = total_monthly_capacity - total_spots_taken
# Division: share 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, the monthly cost, the total monthly cost with the enrollment fee, and the average daily cost for the Recovery Center.
Code Runner Challenge
3.03 HOMEWORK - Recovery Center Cost Report
View IPYNB Source
# CODE_RUNNER: 3.03 HOMEWORK - Recovery Center Cost Report
cost_per_session = 35
sessions_per_week = 3
weeks_per_month = 4
enrollment_fee = 75
weekly_cost = cost_per_session * sessions_per_week
monthly_cost = weekly_cost * weeks_per_month
total_cost_with_fee = monthly_cost + enrollment_fee
average_daily_cost = monthly_cost / 30
print("Weekly Cost:", weekly_cost)
print("Monthly Cost:", monthly_cost)
print("Total Cost with Fee:", total_cost_with_fee)
print("Average Daily Cost:", average_daily_cost)
Homework Results
Weekly Cost: 105
Monthly Cost: 420
Total Cost with Fee: 495
Average Daily Cost: 14.0