2.4.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: Variables and f-strings
# A help desk team tracks one short batch of support tickets.
# Create a variable named remaining_tickets.
# Create a variable named resolution_rate that stores the percent resolved today.
# Print exactly these three lines, using an f-string for each line:
# Team: data services
# Remaining tickets: 13
# Resolution rate: 27.8%
team = "data services"
open_tickets = 18
resolved_today = 5
escalated = 2
### Your code starts here.
### Your code ends here.
Team: data services
Remaining tickets: 13
Resolution rate: 27.8%
### Question 2: Numeric operators
# The variables below describe a small order.
# Calculate subtotal, tax, and total.
# Calculate within_budget as a Boolean value.
# Print exactly these four lines:
# Subtotal: 51.0
# Tax: 4.21
# Total: 55.21
# Within budget: True
notebook_price = 12.50
pen_price = 8.75
sticker_price = 4.25
quantity = 2
tax_rate = 0.0825
budget = 60
### Your code starts here.
### Your code ends here.
Subtotal: 51.0
Tax: 4.21
Total: 55.21
Within budget: True
### Question 3: Type conversion and built-in functions
# The values below are strings because they came from a web form.
# Convert each value to an integer.
# Use sum(), len(), max(), and type() to print exactly these four lines:
# Total responses: 46
# Average responses: 11.5
# Largest batch: 15
# Converted first value type: <class 'int'>
day1_text = "12"
day2_text = "9"
day3_text = "15"
day4_text = "10"
### Your code starts here.
### Your code ends here.
Total responses: 46
Average responses: 11.5
Largest batch: 15
Converted first value type: <class 'int'>
### Question 4: Strings and Boolean expressions
# Use the variables below to build a small account check.
# Create greeting by combining "Hello, " with first_name and "!".
# Create first_code as the first character in access_code.
# Create code_prefix as the first two characters in access_code.
# Create eligible as a Boolean expression that is True only when:
# account_active is True, login_count is at least 3, and access_code is not empty.
# Print exactly these four lines:
# Greeting: Hello, Maya!
# First code: A
# Code prefix: A7
# Eligible: True
first_name = "Maya"
access_code = "A7Z9"
account_active = True
login_count = 3
### Your code starts here.
### Your code ends here.
Greeting: Hello, Maya!
First code: A
Code prefix: A7
Eligible: True
### Question 5: Collection types
# Use a list, set, dictionary, and tuple to summarize the fruit data.
# Create unique_fruits by converting fruits to a set.
# Print the unique fruits with sorted(unique_fruits) so they appear as a list in alphabetical order.
# Create price_pair as a tuple containing "banana" and its price.
# Print exactly these four lines:
# Fruit count: 4
# Unique fruits: ['apple', 'banana', 'cherry']
# Banana price: 0.5
# Price pair: ('banana', 0.5)
fruits = ["apple", "banana", "apple", "cherry"]
fruit_prices = {"apple": 0.75, "banana": 0.50, "cherry": 1.25}
### Your code starts here.
### Your code ends here.
Fruit count: 4
Unique fruits: ['apple', 'banana', 'cherry']
Banana price: 0.5
Price pair: ('banana', 0.5)
Question 1
Question 2
Question 3
Question 4
Question 5