3.3.2. Lab#
Use this assignment to practice the chapter’s concepts and coding skills in runnable Python code.
Sign in from the account menu before you start working on the assignment.
Write and run your code directly in the coding cells.
Multiple submissions are allowed. The highest score is kept.
### Question 1: Unit conversion with modulus and floor division
# An app tracks a user's total screen time in minutes for the month.
# Convert total_minutes into days, hours, and minutes using // and %.
# Print exactly these three lines:
# Days: 2
# Hours: 18
# Minutes: 40
total_minutes = 4000
### Your code starts here.
### Your code ends here.
### Question 2: Nested conditionals for a loyalty tier
# A store assigns a loyalty tier based on account status and spending.
# If account_active is False, tier is "Inactive".
# Otherwise, use nested conditionals on total_spent:
# >= 1000 -> "Platinum", >= 500 -> "Gold", >= 100 -> "Silver", else "Bronze".
# Print exactly these two lines:
# Customer: Jordan Lee
# Tier: Gold
customer_name = "Jordan Lee"
account_active = True
total_spent = 640.50
### Your code starts here.
### Your code ends here.
### Question 3: For-loop accumulator with a condition
# daily_sales lists a store's revenue for each day this week.
# Loop through daily_sales. For every day that is at least sales_target,
# add 1 to qualifying_days and add the day's sales to total_qualifying_sales.
# Print exactly these two lines:
# Qualifying days: 3
# Total qualifying sales: 1760
daily_sales = [420, 150, 610, 90, 730, 260]
sales_target = 300
qualifying_days = 0
total_qualifying_sales = 0
### Your code starts here.
### Your code ends here.
### Question 4: While loop until a savings goal is reached
# Each month, savings_total grows by growth_rate and then monthly_deposit is added.
# Use a while loop that repeats while savings_total is below goal.
# Count the number of months in the variable months.
# Print exactly these two lines (savings formatted to 2 decimal places):
# Months needed: 5
# Final savings: $2071.21
savings_total = 1000
monthly_deposit = 200
growth_rate = 0.01
goal = 2000
months = 0
### Your code starts here.
### Your code ends here.
### Question 5: Conditional expression for shipping fee
# An order qualifies for free shipping once order_total reaches free_shipping_threshold.
# Use a single conditional expression (ternary) to set shipping_fee:
# 0 if the order qualifies, otherwise 5.99.
# Print exactly these two lines (both formatted to 2 decimal places):
# Order total: $42.50
# Shipping fee: $5.99
order_total = 42.50
free_shipping_threshold = 50
### Your code starts here.
### Your code ends here.
Question 1
Question 2
Question 3
Question 4
Question 5