Question: Question 2 (5 points): Purpose: To practice creating and manipulating lists with list comprehensions. Degree of Difficulty: Mostly Easy In a4q2-starter.py you are given a

Question 2 (5 points): Purpose: To practice creating and manipulating lists with list comprehensions. Degree of Difficulty: Mostly Easy In a4q2-starter.py you are given a definition of a list of lists. Each sublist contains three pieces of in- formation on one famous prairie pirate - their pirate name, the number of sacks of assorted grains they have plundered from unsuspecting farmers in the last year, and a Boolean value indicating whether they Like parrots. Create the following list comprehensions where indicated by comments in the provided file a4q2-starter.py. Note that you only need to create the appropriate list comprehensions, you do not need to print them out (though you may want to for testing purposes). (a) Use a single list comprehension to create a list of strings of the pirate names who plundered more than 400 sacks of assorted grains. (b) Use a single list comprehension to create a list of strings of the pirate names who don't like parrots. (c) Suppose that the average market value of a sack of grain is $42. Use a single list comprehension to create a list of integers of the market values of each pirate's grain. (d) Use a single list comprehension to create a list of lists where each sublist consists of a pirate's name, and the value of his/her plundered sacks of grain (calculate grain values as in part (c)), but only include those pirates who like parrots. What to Hand In Rename your completed a4q2-starter.py file to a4q2.py 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)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
