1.3.2. Lab#
Use this lab to practice the chapter’s coding skills in runnable Python code.
Sign in from the account menu before you start working on the lab.
Launch Live Code (the rocket) to write and run code in the coding cells.
Multiple submissions are allowed. The highest score is kept.
### Question 1: First runnable program
# Create a variable named course_name and store "ThinkPy" in it.
# Create a variable named chapter_number and store 1 in it.
# Print exactly two lines:
# ThinkPy Chapter 1
# Python is running.
### Your code starts here.
### Your code ends here.
ThinkPy Chapter 1
Python is running.
### Question 2: Expressions and assignment statements
# The variables below describe a short reading plan.
# Write assignment statements that calculate total_pages and average_pages_per_day.
# Print both values. Use round(average_pages_per_day, 2) for the average.
hours = 6
pages_per_hour = 14
review_pages = 9
days = 5
### Your code starts here.
### Your code ends here.
Total pages: 93
Average per day: 18.6
### Question 3: Formatted output with built-in functions
# A weather station recorded the temperatures below for one city.
# Use len(), max(), min(), sum(), and round() to summarize the readings.
# Print exactly these two lines:
# Austin: 4 readings, high 23.0, low 19.5
# Austin,4,21.5
# Use an f-string for the first line, with max() and min() called inside the braces.
# Use print() with sep="," for the second line. The last value is the average
# temperature rounded to 1 decimal place.
city = "Austin"
temps = [21.5, 23.0, 19.5, 22.0]
### Your code starts here.
### Your code ends here.
Austin: 4 readings, high 23.0, low 19.5
Austin,4,21.5
### Question 4: Convert input text and pack an order
# The variables below simulate text a user typed into input() for an order.
# Convert count_text to an integer named item_count.
# Convert price_text to a float named unit_price.
# Each box holds box_size items. Use // to calculate full_boxes and %
# to calculate loose_items (the items left over after filling full boxes).
# Calculate total_cost as item_count * unit_price, rounded to 2 decimal places.
# Use f-strings to print exactly these three lines:
# Full boxes: 3
# Loose items: 5
# Total cost: 109.25
count_text = "23"
price_text = "4.75"
box_size = 6
### Your code starts here.
### Your code ends here.
Full boxes: 3
Loose items: 5
Total cost: 109.25
### Question 5: Number systems and character encoding
# A simple inventory system uses product code "C" and item number 64.
# Save the decimal code for "C" in c_decimal using ord().
# Save the binary representation of c_decimal in c_binary using bin().
# Save the hexadecimal representation of item_number in item_hex using hex().
# Print c_decimal, c_binary, and item_hex.
item_number = 64
### Your code starts here.
### Your code ends here.
C decimal: 67
C binary: 0b1000011
Item hex: 0x40
Question 1
Question 2
Question 3
Question 4
Question 5