1.3.3. Homework#
Use these questions after class to check your understanding of the chapter concepts and coding skills.
Sign in from the account menu before you start working on the homework.
Complete all true/false and coding questions before you submit the homework.
Launch Live Code (the rocket) to write and run code in the coding cells.
Multiple submissions are allowed. The highest score is kept.
1. Programs
A manager asks an analyst to write a repeatable set of Python instructions that prepares the weekly sales report. Calling that set of instructions a program is appropriate.
2. Algorithms
Before assigning a dashboard task, a team lead sketches the step-by-step logic for cleaning, grouping, and summarizing customer records without choosing Python syntax yet. That sketch can still be an algorithm.
3. Syntax
A supervisor reviews a script that has the right business logic but missing parentheses and mismatched quotes. Because the business logic is correct, Python syntax rules do not matter for whether the script can run.
4. Comments
A project manager asks the team to add notes explaining why a pricing rule exists. If those notes are written as Python lines starting with #, they normally document the script without changing what runs.
5. Input Values
An operations form asks for the number of units to reorder. If a Python script reads that value with input(), Python automatically treats it as a number whenever the next line multiplies it by a price.
### 6. Fix a Syntax Error
# The code below contains one syntax error, a missing closing parenthesis:
# print("ThinkPy homework"
# print("Chapter 1 is about first programs")
# Write the corrected version so it prints exactly:
# ThinkPy homework
# Chapter 1 is about first programs
### Your code starts here.
### Your code ends here.
ThinkPy homework
Chapter 1 is about first programs
### 7. Update a Running Count
# The lab asked you to calculate values once. Here, update a variable as a count changes.
# Start with open_tickets. Add new_tickets, subtract closed_tickets, and print exactly:
# Open tickets: 9
open_tickets = 12
new_tickets = 5
closed_tickets = 8
### Your code starts here.
### Your code ends here.
Open tickets: 9
### 8. Inspect Converted Input
# The lab converted text input to a number. Here, confirm the type changes after conversion.
# Convert quantity_text to an integer named quantity.
# Print exactly:
# Before: <class 'str'>
# After: <class 'int'>
quantity_text = "42"
### Your code starts here.
### Your code ends here.
Before: <class 'str'>
After: <class 'int'>
### 9. Write a Stakeholder Message
# The lab practiced formatted output. Here, write a short message for a business reader.
# Use an f-string and the variables below to print exactly:
# North region needs 6 follow-up calls.
region = "North"
follow_up_calls = 6
### Your code starts here.
### Your code ends here.
North region needs 6 follow-up calls.
### 10. Build an Audit Tag
# The lab printed separate number-system and character-code values.
# Here, combine an initial, its numeric code, and a hex item number into one tag.
# Use ord(), str(), and hex() to print exactly:
# Audit tag: A-65-0xff
initial = "A"
item_number = 255
### Your code starts here.
### Your code ends here.
Audit tag: A-65-0xff