Question
Python 3.6, confusion Starter Code: #CMPT141 Assignment 4 Q3 #To practice creating and manipulating lists with list comprehensions. #Starter code SPL_Patrons = [ ['Kim Tremblay',
Python 3.6, confusion
Starter Code:
#CMPT141 Assignment 4 Q3
#To practice creating and manipulating lists with list comprehensions.
#Starter code
SPL_Patrons = [
['Kim Tremblay', 134, True],
['Emily Wilson', 42, False],
['Jessica Smith', 215, True],
['Alex Roy', 151, True],
['Sarah Khan', 105, False],
['Samuel Lee', 220, True],
['William Brown', 24, False],
['Ayesha Qureshi', 199, True],
['David Martin', 56, True],
['Ajeet Patel',69, False]
]
# part a)
good_readers = [] # Write your list comprehension for part (a) here.
# part b)
not_teenagers = [] # Write your list comprehension for part (b) here.
# part c)
saved_amount = [] # Write your list comprehension for part (c) here.
# part d)
names_and_saved_amount = [] # Write your list comprehension for part (d) here.
print(good_readers)
print(not_teenagers)
print(saved_amount)
print(names_and_saved_amount)
Question 3 (5 points): Purpose: To practice creating and manipulating lists with list comprehensions. Degree of Difficulty: Mostly Easy In a4q3-starter py you are given a definition of a list of lists. Each sublist contains three pieces of informa- tion about the library patrons at Saskatoon Public library (SPD- patron's name, the number of books they have borrowed throughout the last year, and a Boolean value indicating whether they are under 20. Create the following list comprehensions where indicated by comments in the provided file a4q3-starter.py (a) Use a single list comprehension to create a list of the patron names who borrowed more than 100 books last year. (b) Use a single list comprehension to create a list of the patron names who are not under 20. (c) Suppose that a patron saves on average $9.95 by borrowing a book instead of buying it. Use a single list comprehension to create a list of the amount saved for each patron. (d) Use a single list comprehension to create a list of lists where each sublist consists of a patron's name, and the total amount he/she saved last year as in part (c), but only include those patrons who are under 20 What to Hand In Rename your completed a4q3-starter py file to a4q3.py and submit it. Evaluation 1 mark each for parts (a), (b), and (c). 2 marks for part (d)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started