Homework

5.4.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. Chart Choice

A manager comparing revenue across regions would usually start with a comparison chart such as a bar chart.

Hide code cell source

### Solution
# True
# Bar charts support comparisons across categories.

2. Line Charts

A line chart is usually appropriate when the business question focuses on change over time.

Hide code cell source

### Solution
# True
# Line charts emphasize trends across ordered time points.

3. Scatterplots

A scatterplot is mainly used to show the parts of a whole, so it is the default choice for market share percentages.

Hide code cell source

### Solution
# False
# Scatterplots show relationships between two quantitative variables.

4. Outliers

A chart can reveal an unusual sales value that should be investigated before a report is finalized.

Hide code cell source

### Solution
# True
# Visualizations help analysts notice outliers and patterns.

5. Labels

Removing axis labels usually makes a chart easier for a business audience to interpret.

Hide code cell source

### Solution
# False
# Clear labels usually make charts easier to interpret.
### 6. Chart Recommendation Count
# Count how many questions should use each chart type.
# Print exactly:
# Bar charts: 2
# Line charts: 1
chart_choices = ["bar", "line", "bar", "scatter"]

### Your code starts here.



### Your code ends here.

Hide code cell source

### Solution
chart_choices = ["bar", "line", "bar", "scatter"]

bar_charts = chart_choices.count("bar")
line_charts = chart_choices.count("line")

print("Bar charts:", bar_charts)
print("Line charts:", line_charts)
Bar charts: 2
Line charts: 1
### 7. Axis Range
# Calculate the range needed for the y-axis values.
# Print exactly:
# Minimum sales: 80
# Maximum sales: 140
sales = [95, 120, 80, 140]

### Your code starts here.



### Your code ends here.

Hide code cell source

### Solution
sales = [95, 120, 80, 140]

print("Minimum sales:", min(sales))
print("Maximum sales:", max(sales))
Minimum sales: 80
Maximum sales: 140
### 8. Scatter Pairs
# Pair ad spending and revenue values for a scatterplot.
# Print exactly:
# First pair: [10, 80]
# Pair count: 3
ad_spend = [10, 15, 20]
revenue = [80, 110, 150]

### Your code starts here.



### Your code ends here.

Hide code cell source

### Solution
ad_spend = [10, 15, 20]
revenue = [80, 110, 150]

pairs = []
index = 0
for value in ad_spend:
    pairs.append([value, revenue[index]])
    index = index + 1

print("First pair:", pairs[0])
print("Pair count:", len(pairs))
First pair: [10, 80]
Pair count: 3
### 9. Emphasis Color
# Choose a highlight color for the target region and gray for the others.
# Print exactly:
# Colors: ['gray', 'red', 'gray']
regions = ["East", "West", "South"]
target_region = "West"

### Your code starts here.



### Your code ends here.

Hide code cell source

### Solution
regions = ["East", "West", "South"]
target_region = "West"

colors = []
for region in regions:
    if region == target_region:
        colors.append("red")
    else:
        colors.append("gray")

print("Colors:", colors)
Colors: ['gray', 'red', 'gray']
### 10. Misleading Scale Flag
# Flag the chart if the y-axis does not start at zero for a bar chart.
# Print exactly:
# Scale warning: True
chart_type = "bar"
y_axis_start = 75

### Your code starts here.



### Your code ends here.

Hide code cell source

### Solution
chart_type = "bar"
y_axis_start = 75

scale_warning = chart_type == "bar" and y_axis_start != 0
print("Scale warning:", scale_warning)
Scale warning: True