e Chegg Study | Guided SX \\ ^ Home CSecure https/jhub.cas.mcmaster.ca/user/meht
ID: 3732796 • Letter: E
Question
e Chegg Study | Guided SX ^ Home CSecure https/jhub.cas.mcmaster.ca/user/mehtaa13/notebooks/assign9 section1/major4_v1.ipynb jupytermajor4_v1 Last Checkpoint: a few seconds ago (autosaved) Control PanelLogout File Edit View Insert Cell Kemel Help Not TrustedPython 3 O Background This assignment deals with interpreting a table of weather simulation data, to predict the daily weather. Say that when a weather simulation program runs, it creates a row of output in the form of a Python list: row [hour, temperature, relHumidity, [cloudcover, cloudHeight], [windSpdLow, windSpdHigh]] where hour is an integer between 0 and 23 representing hours past midnight, temperature is a float in Celsius, relHumidity and cloudCover are percents (floats) between 0 and 1, cloudHeight is an integer in metres, and both windSpdLow and windSpdHigh are floats in km/h. The simulation runs n times, and returns the final result as a list of rows data -[ row 1, row 2, ..., row n Your program will contain a set of functions that can be used to interpret this list of simulation rows. Design, implement, and test a program that satisfies the requirements below. Requirements 1. Implement the function isTempUnder (row, temp), which takes ONE ROW of a weather simulation (hour, temp, etc.]) and a float temp, and retuns True If temperature for that row is below temp, False otherwise 2. Implement the function isHumidityOver(row, percent), which takes ONE ROW of a weather simulation ([hour, temp, etc.) and a float percent, and returns True if relHumidity for that row is above percent, False otherwise 3. Implement the function iscloudHeightUnder (row, height), which takes ONE ROW of a weather simulation (hour, temp, etc.]) and an integer 11:34 AM O Type here to search 2018-03-19Explanation / Answer
Here is the python code for all the functions. Execute with sample data.
#!/usr/bin/python
def isTempUnder(row, temp):
if row[1] < temp:
return True
else:
return False
def isHumidityOver(row, percent):
if row[2] > percent:
return True
else:
return False
def isCloudHeightUnder(row, height):
(cloudCover, cloudHeight) = row[3]
if cloudHeight < height:
return True
else:
return False
def snowChance(data):
totRows = data.__len__()
snowCnt = 0.0
hours = []
for row in data:
relHumidity = row[2]
temprature = row[1]
(cloudCover, cloudHeight) = row[3]
if relHumidity > 0.8 and temprature < 0.5 and cloudHeight < 1000:
snowCnt += 1
hours.append(row[0])
hours.sort()
chance = snowCnt / totRows
if snowCnt == 0:
time = 0
else:
time = hours[-1] - hours[0]
return [chance, time]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.