3.4.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: Array Shape and Total
# Represent the weekly sales table as a nested list.
# Calculate rows, columns, and the total number of values.
# Print exactly:
# Rows: 3
# Columns: 4
# Values: 12
sales = [[18, 21, 19, 24], [15, 17, 16, 20], [22, 25, 23, 28]]
### Your code starts here.
### Your code ends here.
Rows: 3
Columns: 4
Values: 12
### Question 2: Vectorized Price Change
# Add the same price increase to each base price.
# Store the adjusted prices in a list named adjusted_prices.
# Print exactly:
# Adjusted prices: [13, 17, 21, 25]
base_prices = [10, 14, 18, 22]
increase = 3
### Your code starts here.
### Your code ends here.
Adjusted prices: [13, 17, 21, 25]
### Question 3: Boolean Mask Selection
# Build a list of sales values that meet or exceed the target.
# Store the result in selected_sales.
# Print exactly:
# Selected sales: [120, 135, 150]
sales = [95, 120, 88, 135, 150]
target = 100
### Your code starts here.
### Your code ends here.
Selected sales: [120, 135, 150]
### Question 4: Universal Function Style
# Square each demand error and total the squared errors.
# Store the squared values in squared_errors.
# Print exactly:
# Squared errors: [4, 1, 9, 16]
# Total squared error: 30
errors = [2, -1, 3, -4]
### Your code starts here.
### Your code ends here.
Squared errors: [4, 1, 9, 16]
Total squared error: 30
### Question 5: Reproducible Sample Summary
# Treat the list below as a saved random sample.
# Calculate the sample size and sample mean.
# Print exactly:
# Sample size: 5
# Sample mean: 42.0
sample = [38, 41, 45, 39, 47]
### Your code starts here.
### Your code ends here.
Sample size: 5
Sample mean: 42.0
Question 1
Question 2
Question 3
Question 4
Question 5