Homework

2.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. Variables

A data team stores the current file name in source_file and the number of rows in row_count. Those variable names make the script easier to read than names such as x and y.

2. Type Conversion

A web form sends the string "42" for a response count. Python can always use that string directly in numeric addition without conversion.

3. Numeric Operators

When a report needs whole hours and leftover minutes from a count of seconds, integer division and the remainder operator can help separate the parts.

4. Boolean Expressions

A dashboard rule such as score >= 80 and account_active produces a Boolean value that can represent whether a record is eligible.

5. Collection Types

A tuple is the best basic collection type when a program must repeatedly append new daily sales values to the same object.

### 6. Format a report line
# Use the variables below.
# Print exactly:
# Report: sales has 128 rows and 5 columns
report_name = "sales"
row_count = 128
column_count = 5

### Your code starts here.



### Your code ends here.
### 7. Convert seconds to time parts
# Use numeric operators to split total_seconds into hours, minutes, and seconds.
# Print exactly these three lines:
# Hours: 3
# Minutes: 28
# Seconds: 20
total_seconds = 12500

### Your code starts here.



### Your code ends here.
### 8. Convert text prices
# Convert the two text prices to floating-point numbers.
# Calculate total and round it to two decimal places.
# Print exactly these three lines:
# Total: 25.49
# First price type: <class 'float'>
# Total type: <class 'float'>
base_price_text = "19.99"
fee_text = "5.50"

### Your code starts here.



### Your code ends here.
### 9. Slice a code string
# Use indexing, slicing, and len() with the code below.
# Print exactly these four lines:
# Prefix: PY
# Year: 2026
# Label: LAB
# Code length: 11
course_code = "PY-2026-LAB"

### Your code starts here.



### Your code ends here.
### 10. Summarize a small collection
# Use the list and dictionary below.
# Create unique_names as a sorted list of unique names.
# Create bob_pair as a tuple with "Bob" and Bob's score.
# Print exactly these four lines:
# Submission count: 4
# Unique names: ['Ana', 'Bob', 'Chen']
# Bob score: 88
# Bob pair: ('Bob', 88)
names = ["Ana", "Bob", "Ana", "Chen"]
scores = {"Ana": 91, "Bob": 88, "Chen": 95}

### Your code starts here.



### Your code ends here.