1.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. 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.
### 7. Fix a NameError
# A program that prints an order total failed with this error message:
# NameError: name 'quantty' is not defined
# Read the last line of the message and find the misspelled name in the broken code below.
# Write the corrected program so that it prints exactly:
# Total: 30
#
# Broken code (do not run it):
# price = 10
# quantity = 3
# print("Total:", price * quantty)
### Your code starts here.
### Your code ends here.
### 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.
### 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.
# Print exactly:
# North region needs 6 follow-up calls.
region = "North"
follow_up_calls = 6
### Your code starts here.
### Your code ends here.
### 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().
# Print exactly:
# Audit tag: A-65-0xff
initial = "A"
item_number = 255
### Your code starts here.
### Your code ends here.