Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

Why are taxes important in capital budgeting?

Answered: 1 week ago

Question

What do you think accounts for the fact that turnover is low?

Answered: 1 week ago