Homework

3.3.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. Branching

A product manager says a rule should send active premium customers to priority review and all other customers to standard review. An if/else statement is an appropriate way to express that decision.

2. Comparison Operators

An analyst can use score >= 90 to produce a Boolean value before deciding whether a record receives an honors label.

3. Loop Accumulators

A reporting script that totals only approved invoices can use a loop with an accumulator that increases when each invoice qualifies.

4. While Loops

A while loop automatically stops after one pass even when its condition remains true.

5. Conditional Expressions

A conditional expression is best used for large multi-step workflows with many statements in each branch.

### 6. Route a service ticket
# Use `if`, `elif`, and `else` to classify the ticket below with these rules:
# - If age_days is at least 7 and customer_tier is "gold", the priority is "urgent".
# - Otherwise, if age_days is at least 7, the priority is "high".
# - Otherwise, the priority is "normal".
# Print exactly these two lines:
# Ticket age: 9
# Priority: urgent
age_days = 9
customer_tier = "gold"

### Your code starts here.



### Your code ends here.
### 7. Count qualifying sales
# Use a `for` loop and an accumulator to count sales of at least 500.
# Print exactly these two lines:
# Qualifying sales: 3
# Qualifying total: 2190
sales = [320, 750, 120, 810, 630]

### Your code starts here.



### Your code ends here.
### 8. Stop at a budget limit
# Use a `while` loop to add weekly savings until the balance reaches at least 500.
# Print exactly these two lines:
# Weeks: 6
# Balance: 540
balance = 180
weekly_savings = 60

### Your code starts here.



### Your code ends here.
### 9. Create pass/fail labels
# Use a loop and a conditional expression to build the labels list.
# A score of 75 or higher gets "pass"; any lower score gets "review".
# Print exactly this line:
# Labels: ['pass', 'review', 'pass', 'review']
scores = [84, 62, 91, 70]

### Your code starts here.



### Your code ends here.
### 10. Build a multiplication row
# Use a loop to create products for 4 times 1 through 5.
# Print exactly this line:
# Row: [4, 8, 12, 16, 20]
factor = 4

### Your code starts here.



### Your code ends here.