2.6.3. Homework#
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.
1. List Indexing
If departments = ["Sales", "HR", "Ops"], then departments[0] refers to "Sales".
2. String and Number Operations
A dashboard import reads quantity as the string "12". Python will always treat "12" + 3 as the number 15 without conversion.
3. Conditional Business Rules
An inventory script uses an if statement to reorder only when inventory is below the reorder point. This is a reasonable use of conditional logic.
4. Looping Through Sales
A for loop over a list of daily sales is useful when the same calculation should run once for each day.
5. Dictionary Keys
A dictionary that stores product prices must use only integer keys; text keys such as product names are invalid.
### 6. Format a Revenue Message
# Use the variables below to calculate profit and print exactly:
# East profit: 375
region = "East"
revenue = 1250
cost = 875
### Your code starts here.
### Your code ends here.
East profit: 375
### 7. Classify Customer Volume
# Use if/elif/else to classify the customer count.
# Set segment to "high" when customers is at least 100,
# "medium" when customers is at least 50, and "low" otherwise.
# Print exactly:
# Segment: medium
customers = 72
### Your code starts here.
### Your code ends here.
Segment: medium
### 8. Count Until Closing
# Use a while loop to add customer counts until the sentinel value 0 appears.
# Print exactly:
# Days counted: 2
# Customers before closing: 80
daily_customers = [42, 38, 0, 51]
### Your code starts here.
### Your code ends here.
Days counted: 2
Customers before closing: 80
### 9. Count Product Categories
# Count each category in the purchases list using a dictionary.
# Print exactly:
# Software purchases: 3
# Service purchases: 2
purchases = ["Software", "Service", "Software", "Hardware", "Service", "Software"]
### Your code starts here.
### Your code ends here.
Software purchases: 3
Service purchases: 2
### 10. Reusable Revenue Per Employee
# Define revenue_per_employee(revenue, employees).
# Return revenue divided by employees.
# Print exactly:
# Revenue per employee: 250.0
def revenue_per_employee(revenue, employees):
### Your code starts here.
pass
### Your code ends here.
metric = revenue_per_employee(5000, 20)
print("Revenue per employee:", metric)
Revenue per employee: None
Revenue per employee: 250.0