1.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: 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.
### 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.
### 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.
### Question 4: Convert input text and compute an order total
# 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.
# Calculate subtotal as item_count * unit_price.
# Calculate total_with_tax as subtotal * (1 + tax_rate), rounded to 2 decimal places.
# Use f-strings.
# Print exactly these three lines:
# Items: 23
# Subtotal: 109.25
# Total with tax: 117.99
count_text = "23"
price_text = "4.75"
tax_rate = 0.08
### Your code starts here.
### Your code ends here.
### 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.
Question 1
Question 2
Question 3
Question 4
Question 5