Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started