Homework

1.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. Data Science in a Retail Decision

A retail team combines sales records, Python summaries, statistics, merchandising knowledge, and a manager-facing recommendation to decide which products to reorder. Calling this work data science is appropriate.

Hide code cell source

### Solution
# True
# The work combines data, computing, statistics, domain expertise, and communication for a decision.

2. Data Without Context

A marketing analyst has click data but does not know the campaign goal, product margins, or customer segment. The analyst can still decide the best campaign from the data alone.

Hide code cell source

### Solution
# False
# The data needs domain context before it can support a useful decision.

3. Descriptive Questions

A store manager asks, “How many returns did each product category have last month?” This is mainly a descriptive data science question.

Hide code cell source

### Solution
# True
# The question summarizes what already happened.

4. Predictive and Prescriptive Questions

An operations director asks, “Which shipments are most likely to arrive late next week?” This is mainly a prescriptive question.

Hide code cell source

### Solution
# False
# The question estimates a future outcome, so it is predictive. A prescriptive question would recommend an action.

5. Formal Language Rules

A finance script has the right formula but is missing a closing quote in one print() statement. Because the business idea is correct, Python syntax rules will not affect whether the program runs.

Hide code cell source

### Solution
# False
# Python is a formal language; syntax errors can stop a program before the business logic runs.
### 6. Classify Management Questions
# A customer success team is reviewing subscription cancellations.
# Store the correct label for each question: descriptive, predictive, or prescriptive.
# Then print each label with the question name.
#
# question_a: How many customers canceled last month?
# question_b: Which customers are most likely to cancel next month?
# question_c: Which retention offer should we send first?

question_a = ""
question_b = ""
question_c = ""

### Your code starts here.



### Your code ends here.

Hide code cell source

### Solution
question_a = "descriptive"
question_b = "predictive"
question_c = "prescriptive"

print("Question A:", question_a)
print("Question B:", question_b)
print("Question C:", question_c)
Question A: descriptive
Question B: predictive
Question C: prescriptive
### 7. Write a Stakeholder Status Line
# The lab asked you to print technical values. Here, turn values into a concise status line.
# Use an f-string and the variables below to print exactly:
# North store has 7 late shipments out of 80.

store = "North"
late_shipments = 7
total_shipments = 80

### Your code starts here.



### Your code ends here.

Hide code cell source

### Solution
store = "North"
late_shipments = 7
total_shipments = 80

print(f"{store} store has {late_shipments} late shipments out of {total_shipments}.")
North store has 7 late shipments out of 80.
### 8. Fix a Syntax Error
# The lab asked you to write correct statements. Here, practice recognizing broken syntax.
# The two lines below have syntax problems:
# print("DSM homework"
# print("Syntax fixed.")
# Write corrected code that prints exactly:
# DSM homework
# Syntax fixed.

### Your code starts here.



### Your code ends here.

Hide code cell source

### Solution
print("DSM homework")
print("Syntax fixed.")
DSM homework
Syntax fixed.
### 9. Build an Inventory Code
# The lab printed separate number-system and character-code values.
# Here, combine those pieces into one inventory code.
# Use ord() and hex() with the variables below to print exactly:
# Inventory code: R-82-0x2d

category = "R"
item_id = 45

### Your code starts here.



### Your code ends here.

Hide code cell source

### Solution
category = "R"
item_id = 45
category_code = ord(category)
item_hex = hex(item_id)

print(f"Inventory code: {category}-{category_code}-{item_hex}")
Inventory code: R-82-0x2d
### 10. Calculate Audit Metrics
# The lab calculated an order total. Here, calculate simple management metrics from case counts.
# Use the variables below to calculate open_cases and closure_rate.
# Print exactly:
# Open cases: 17
# Closure rate: 0.67

starting_cases = 20
new_cases = 7
closed_cases = 10
assigned_cases = 15

### Your code starts here.



### Your code ends here.

Hide code cell source

### Solution
starting_cases = 20
new_cases = 7
closed_cases = 10
assigned_cases = 15

open_cases = starting_cases + new_cases - closed_cases
closure_rate = closed_cases / assigned_cases

print("Open cases:", open_cases)
print("Closure rate:", round(closure_rate, 2))
Open cases: 17
Closure rate: 0.67