Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Purpose: To practice creating and manipulating lists with list comprehensions. Degree of Difficulty: Mostly Easy In a5q2-starter.py you are given a definition of a list
Purpose: To practice creating and manipulating lists with list comprehensions. Degree of Difficulty: Mostly Easy In a5q2-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 (SPL) - 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 a5q2-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 $11.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 a5q2-starter.py file to a5q2.py add the required code and submit it. Evaluation -1 mark for missing name, NSID and student number at top of file 1 mark each for parts (a), (b), and (c). 2 marks for part (d). # 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 6) 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)
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