Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python via PyCharm - - Starter file: # Historical Weather for February 2018 in Saskatoon # Daily Data is in the Format [date, day, high,

Python via PyCharm

-

image text in transcribed

-

Starter file:

# Historical Weather for February 2018 in Saskatoon # Daily Data is in the Format [date, day, high, low] weather_yxe_2018 = [ ["2018-02-01","Thursday",-18.6,-30.6,], ["2018-02-02","Friday",-19.6,-23.4,], ["2018-02-03","Saturday",-22.3,-30.4,], ["2018-02-04","Sunday",-17.4,-27.7,], ["2018-02-05","Monday",-16.2,-25.3,], ["2018-02-06","Tuesday",-16.6,-27.8,], ["2018-02-07","Wednesday",-18.2,-30.5,], ["2018-02-08","Thursday",-18.1,-29.5,], ["2018-02-09","Friday",-15.5,-29.8,], ["2018-02-10","Saturday",-9.4,-19.6,], ["2018-02-11","Sunday",-19.2,-31.2,], ["2018-02-12","Monday",-14.5,-32.4,], ["2018-02-13","Tuesday",2.3,-17.4,], ["2018-02-14","Wednesday",0.1,-19.9,], ["2018-02-15","Thursday",-14.3,-32,], ["2018-02-16","Friday",-7.5,-21.2,], ["2018-02-17","Saturday",-11,-19.6,], ["2018-02-18","Sunday",-14.2,-25.9,], ["2018-02-19","Monday",-15.3,-30.2,], ["2018-02-20","Tuesday",-13.7,-28.6,], ["2018-02-21","Wednesday",-12.3,-31.3,], ["2018-02-22","Thursday",-8.1,-25.3,], ["2018-02-23","Friday",-6.2,-21.5,], ["2018-02-24","Saturday",-2,-14.1,], ["2018-02-25","Sunday",-3.7,-15.4,], ["2018-02-26","Monday",-5.2,-19.3,], ["2018-02-27","Tuesday",-4.4,-13.9,], ["2018-02-28","Wednesday",-0.3,-16.6,] ]

-

-

-

example:

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 = [p[0] for p in prairie_pirates if p[1] > 400 ]

# part b) parrot_haters = [p[0] for p in prairie_pirates if not p[2] ]

# part c) plunder_values = [p[1] * 42 for p in prairie_pirates ]

# part d) names_and_plunder_values = [[p[0], p[1] * 42] for p in prairie_pirates if p[2]]

print(best_plunderers) print(parrot_haters) print(plunder_values) print(names_and_plunder_values)

Purpose: To practice creating and manipulating lists with list comprehensions. Degree of Difficulty: Mostly Easy Some people hate February because it's so cold! In order to prepare ourselves for the month, let's look back at some historical weather data from 2018. Maybe it wasn't as bad as we remember? In a4q2 starter.py you are given a definition of a list of lists. Each sublist contains four pieces of information - the date, day of the week, daily high temperature, daily low temperature Create the following list comprehensions.. (a) Are any days above O? Use a single list comprehension to create a list of the dates where the daily (b) Mondays are the worst. Use a single list comprehension to create a list of the daily low temparatures (c) Some days start cold but get much warmer. Use a single list comprehension to create a list of the (d) But what about the weekend!? Use a single list comprehension to create a list of lists where each sub- high temperature was more than O and print ) the results. for days that are Monday and print ) the results. difference between the daily low and daily high temperature for each date and print) the results. list consists of a date and daily high temperature, but only include dates that are Saturday or Sunday and print ( the results. Note that this question is to test your use of List comprehensions. No marks will be given for solutions that do not use list comprehensions. Please be sure to use print ) to show your results in the console

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

Compare and contrast switches, routers, and gateways.

Answered: 1 week ago