Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python programming def get_weather_report(takeoff,weather): Returns the most recent weather report at or before take-off. The weather is a dictionary whose keys are ISO formatted

Python programming

def get_weather_report(takeoff,weather): """ Returns the most recent weather report at or before take-off. The weather is a dictionary whose keys are ISO formatted timestamps and whose values are weather reports. For example, here is an example of a (small portion of) a weather dictionary: { "2017-04-21T08:00:00-04:00": { "visibility": { "prevailing": 10.0, "units": "SM" }, "wind": { "speed": 13.0, "crosswind": 2.0, "units": "KT" }, "temperature": { "value": 13.9, "units": "C" }, "sky": [ { "cover": "clouds", "type": "broken", "height": 700.0, "units": "FT" } ], "code": "201704211056Z" }, "2017-04-21T07:00:00-04:00": { "visibility": { "prevailing": 10.0, "units": "SM" }, "wind": { "speed": 13.0, "crosswind": 2.0, "units": "KT" }, "temperature": { "value": 13.9, "units": "C" }, "sky": [ { "type": "overcast", "height": 700.0, "units": "FT" } ], "code": "201704210956Z" } ... }, If there is a report whose timestamp matches the ISO representation of takeoff, this function uses that report. Otherwise it searches the dictionary for the most recent report before takeoff. If there is no such report, it returns None. Example: If takeoff was as 8 am on April 21, 2017 (Eastern), this function returns the value for key '2017-04-21T08:00:00-04:00'. If there is no additional report at 9 am, a 9 am takeoff would use this value as well. Parameter takeoff: The takeoff time Precondition: takeoff is a datetime object Paramater weather: The weather report dictionary Precondition: weather is a dictionary formatted as described above """ # HINT: Looping through the dictionary is VERY slow because it is so large # You should convert the takeoff time to an ISO string and search for that first. # Only loop through the dictionary as a back-up if that fails. # Search for time in dictionary # As fall back, find the closest time before takeoff

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions