2.6.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: Order Totals
# A manager is reviewing one customer order.
# Calculate subtotal, discount, and final_total from the variables below.
# Print exactly:
# Subtotal: 180
# Discount: 18.0
# Final total: 162.0
unit_price = 45
quantity = 4
discount_rate = 0.10
### Your code starts here.
### Your code ends here.
Subtotal: 180
Discount: 18.0
Final total: 162.0
### Question 2: Reorder Decision
# Use an if/else statement to decide whether the store should reorder.
# If inventory is less than reorder_point, set decision to "Reorder".
# Otherwise, set decision to "Wait".
# Print exactly:
# Decision: Reorder
inventory = 8
reorder_point = 10
### Your code starts here.
### Your code ends here.
Decision: Reorder
### Question 3: High Sales List
# Use a loop and append() to build a list of sales above the target.
# Store the result in high_sales.
# Print exactly:
# High sales: [340, 410]
# First high sale: 340
sales = [340, 280, 410]
target = 300
### Your code starts here.
### Your code ends here.
High sales: [340, 410]
First high sale: 340
### Question 4: Department Counts
# Count how many employees appear in each department.
# Store the counts in a dictionary named department_counts.
# Print exactly:
# Sales count: 3
# HR count: 1
departments = ["Sales", "HR", "Sales", "Ops", "Sales"]
### Your code starts here.
### Your code ends here.
Sales count: 3
HR count: 1
### Question 5: Reusable Margin Function
# Define a function named calculate_margin that takes revenue and cost.
# The function should return revenue minus cost.
# Call it with revenue 1250 and cost 875.
# Print exactly:
# Margin: 375
def calculate_margin(revenue, cost):
### Your code starts here.
pass
### Your code ends here.
margin = calculate_margin(1250, 875)
print("Margin:", margin)
Margin: None
Margin: 375
Question 1
Question 2
Question 3
Question 4
Question 5