Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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). prairie_pirates = [ ['Tractor Jack', 1000, True], ['Plowshare Pete', 950, False], ['Prairie Lily', 245, True], ['Red River Rosie', 350, True], ['Mad Athabasca McArthur', 842, False}, ['Assiniboine Sally', 620, True], ['Thresher Tom', 150, True], ['Cranky Canola Carl', 499, False] # part a) best_plunderers = [] # Write your list comprehension for part (a) here. # part b) parrot_haters = [] # Write your list comprehension for part (b) here. # part c) plunder_values = [] # Write your list comprehension for part (c) here. # part d) names_and_plunder_values = [] # Write your list comprehension for part (d) here. print(best_plunderers) print (parrot_haters) print (plunder_values) print(names_and_plunder_values)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What do you think of the MBO program developed by Drucker?

Answered: 1 week ago