Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q1) Add a new function called loadTemperatureData. The header of this function is def loadTemperatureData(self, filename). This function uses a loop to load temperatures in

Q1) Add a new function called loadTemperatureData. The header of this function is def loadTemperatureData(self, filename). This function uses a loop to load temperatures in the temperature file (filename) to a list and return the list to the caller.

Modify __init__ function to add one more data attribute temperatureList. Inside __init__ function, call loadTemperatureData function and assign the returned value to temperatureList.

Modify calculateAverage function to use the data attribute temperatureList to calculate average temperature.

Main function remain unchanged.

For Reference:

class TemperatureFile:

def __init__(self, name): self.__fileName = name

def getFileName(self): return self.__fileName

def setFileName(self, name): self.__fileName = name

def calculateAverage(self): # open file and read temperature value on each line # and convert it to float. # Add all temperatures together # and calculate the average. # Handle possible exceptions # return average temperature to the caller. #(15 points) def whatWeather(self, averageTemp): #Use decision structure to print out "Cold" if averageTemp is below 50 #print out "Warm" if averageTemp is between 50 and 80 #print out "Hot" if averageTemp is above 80 #(10 points)

def main(): try: filename = "Temperatures.txt" file = open(filename, 'w') file.write("55 ") file.write("80 ") file.write("100 ") file.close() except IOError: print("Error opening/writing file")

main()

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

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago