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 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)

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

Recommended Textbook for

Online Market Research Cost Effective Searching Of The Internet And Online Databases

Authors: John F. Lescher

1st Edition

0201489295, 978-0201489293

More Books

Students also viewed these Databases questions