Question: Write a class called TemperatureFile. The class has one data attribute __filename Write getter and setter for the data attribute. Write a calculateAverage function (signature

Write a class called TemperatureFile. The class has one data attribute __filename Write getter and setter for the data attribute. Write a calculateAverage function (signature below) to calculate and return average temperature of all temperatures in the file. def calculateAverage(self): Handle possible exceptions

Write a main function: Create a file ('Temperatures.txt) and then use write method to write temperature values on each line. Create an object of the TemperaureFile with the filename (Temperatures.txt) just created. Use the object to call calcuateAverage function and print out the returned average temperature. Handle possible exceptions in main function.

_______________________________________________________

# Create Class class tempearutefile: def __intit__(self, filename): self.__filename = filename

def set_filename(self, filename): self.__filename = filename

def get_filename(self): return self.__filename

def calculateAverage(self, num1,num2,num3): try: total = num1+ num2+ num3 average = total/3 return average # exception errors except ValueError as err: print(err)

except IOError as err: print(err) except Exception as err: print(err) def main(): try: #Getting input from the users num1=float(input("Please enter your first value: ")) num2=float(input("Please enter your second value: ")) num3=float(input("Please enter your third value: ")) #Creating temperatue file test_file= open('Temperatures.txt', 'w') #writing input informatin to the file test_file.write(str(num1 + ' ')) test_file.write(str(num2 + ' ')) test_file.write(str(num3 + ' ')) #closing file test_file.close() temp1 = tempearutefile(test_file) calculateAverage (float(num1),float(num2),float(num3)): print("your average temperatue is:", average) # exception errors except ValueError as err: print(err)

except IOError as err: print(err) except Exception as err: print(err)

#Call to main main()

I am getting an Error. Please help this phyton code. Thanks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!