Wk#8 Please, the code should be in a file in the format and… Wk#8Please, the code should be in a file in the format and have to be 2 codes ( code.py and Mylib.py). Please, test your code before sending it.Overall Feedback1- Do not use any UI or print in the functions. When you include a print, then the code is not reusable anymore and not nestable.2- Save to file or reading the results from a file.You are going to enhance the prior assignment by doing the following:1) Add menu items to write to a file and to read from a file2) create a class Wrfile() with two methods to write the results to a file, and to read the results from a file.The idea is like the sample run below. If the user of your program chooses (7), send the output of allInOne(), which is what you created for menu (6) to a file.If a user chooses (8) you read from a file and display it to a screen.If the file doesn’t exist or empty, make sure to handle that gracefully.Sample output:_______________________________________________________________Enter your Lower range —>1Enter your Higher range —>10Enter your First number —>8Enter your Second number –>2Select one of the following1) Add two numbers2) Subtract two numbers3) Multiply two numbers4) Divide two numbers5) Scalc6) All in one7) Write to a file8) Read from a fileType the number of your selection: 7Sample output:1. Add two numbers2. Subtract two numbers3. Multiply two numbers4. Divide two numbers5. Scalc6. All In Oneres=allInOne(5,2)The results will be return in this format;res is dictionary {“add”:7, “sub”:3, “mult”:10, “div”:2.5)from res, you are going to print5 + 2 = 75 – 2 = 35 * 2 = 105 / 2 = 2.5This is prior code:class Calc: def __init__(self, num1,num2): self.num1 = num1 self.num2 = num2 def allinone(self): try: res = { ‘add’: self.num1 + self.num2, ‘sub’: self.num1 – self.num2, ‘mult’: self.num1 * self.num2, ‘div’: self.num1 / self.num2, } except: print (‘Cannot divide by zero!’) exit() return res def addition(self): return (self.num1 + self.num2) def multiplication(self): return (self.num1 * self.num2) def substraction(self): return (self.num1 – self.num2) def division(self): try: self.num1 / self.num2 except ZeroDivisionError as e: print (‘Error dividing by zero: ‘ + str(e.args)) return (self.num1 / self.num2) def scalc(self,a): (d, c, y) = a.split(‘,’) try: self.num1 = int(d) self.num2 = int(c) except: print (‘Invalid input!’) exit() if y == ‘+’: return self.addition() elif y == ‘-‘: return self.substraction() elif y == ‘*’: return self.multiplication() elif y == ‘/’: return self.division() else: print (‘invalid operator’)def main(): result = 0 menu = [ ‘n1) Add two numbers’, ‘2) Subtraction two numbers’, ‘2) Multiply two numbers’, ‘4) Divide two numbers’, ‘5) Scalc’, ‘6) All in one …’, ‘7) Exit’, ] try: num1 = int(input(‘Enter first number :—> ‘)) num2 = int(input(‘Enter second number :—> ‘)) except: print (‘Invalid input!’) exit() calculator = Calc(num1,num2) for operations in menu: print (operations) ch = input(‘Enter a choice : ‘) if ch == ‘7’: exit() if ch == ‘5’: a = input(“Eg:’num1,num2,operator’:—> “) result = calculator.scalc(a) print(result) main() if ch == ‘1’: result = calculator.addition() print (‘The addition of number {} and {} is {}’.format(calculator.num1,calculator.num2,result)) print(result) elif ch == ‘6’: res = calculator.allinone() num1 = calculator.num1 num2 = calculator.num2 print (‘{} + {} = {}’.format(num1, num2, res[‘add’])) print (‘{} – {} = {}’.format(num1, num2, res[‘sub’])) print (‘{} * {} = {}’.format(num1, num2, res[‘mult’])) print (‘{} * {} = {:.2f}’.format(num1, num2, res[‘div’])) elif ch == ‘3’: result = calculator.multiplication() print (‘The multiplication of number {} and {} is {}’.format(calculator.num1,calculator.num2, result)) elif ch == ‘4’: result = calculator.division() print (‘The division of number {} and {} is {:.2f}’.format(calculator.num1,calculator.num2, result)) elif ch == ‘2’: result=calculator.substraction() print (‘The subtraction of number {} and {} is {:.2f}’.format(calculator.num1,calculator.num2, result)) else: print (‘No valid option chosen!’)if __name__ == ‘__main__’: main()Computer ScienceEngineering & TechnologyPython Programming ENTD 220

Order your essay today and save 20% with the discount code ESSAYHELP