6.4.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. Lists
A project tracker that needs to preserve task order and allow updates is a good fit for a list.
2. Tuples
A function can return a tuple when it needs to return two related values such as a minimum and a maximum.
3. Tuples
You can change the second item of a tuple with t[1] = 5 because tuples are ordered.
4. Aliasing
If two variables refer to the same mutable list, changing the list through one variable can be visible through the other.
5. Shallow Copies
After b = a.copy(), appending to a nested list inside b never changes a.
### 6. Update an ordered list
# Add `"review"` to the end of the tasks list and print exactly this line:
# # Tasks: ['collect', 'clean', 'review']
tasks = ["collect", "clean"]
### Your code starts here.
### Your code ends here.
Tasks: ['collect', 'clean', 'review']
### 7. Unpack tuple records
# Unpack the record and print exactly these three lines:
# # Name: Ana
# # Score: 91
# # Passed: True
record = ("Ana", 91, True)
### Your code starts here.
### Your code ends here.
Name: Ana
Score: 91
Passed: True
### 8. Slice a list
# Use slicing to print the first three and last two numbers. Print exactly these two lines:
# # First three: [3, 8, 1]
# # Last two: [7, 4]
nums = [3, 8, 1, 9, 7, 4]
### Your code starts here.
### Your code ends here.
First three: [3, 8, 1]
Last two: [7, 4]
### 9. Compare copied lists
# Show aliasing versus copying with these steps:
# 1. Make an alias with alias = original.
# 2. Make a copy with backup = original.copy().
# 3. Append 30 through the alias with alias.append(30).
# 4. Print the alias, then the copy.
# Print exactly these two lines:
# # Alias: [10, 20, 30]
# # Copy: [10, 20]
original = [10, 20]
### Your code starts here.
### Your code ends here.
Alias: [10, 20, 30]
Copy: [10, 20]
### 10. Count with a comprehension
# Use sum() with a list comprehension to count scores of 60 or above. Print exactly this line:
# # Passing: 4 of 5
scores = [72, 55, 88, 61, 90]
### Your code starts here.
### Your code ends here.
Passing: 4 of 5