Question: hello, I am creating class that contain all prior functions for python. Can you help me to fix it please? #Mylib class cal: def __init__

hello, I am creating class that contain all prior functions for python. Can you help me to fix it please?

#Mylib

class cal:

def __init__ (self,a: 'cal', b: 'cal'):

self.a=a

self.b=b

def add(self):# Defined function for addition

return self.a+self.b

def mult(self):# Defined function for multiplication

return self.a*self.b

def sub(self):# Defined function for subtract

return self.a-self.b

def div(self):# Defined function for division

return self.a/self.b

def scalc(self,p1):

string1 = p1.split(",")

if string1[2] == "+":

result = addition(float(string1[0]), float(string1[1]))

elif string1[2] == "-":

result = subtraction(float(string1[0]), float(string1[1]))

elif string1[2] == "*":

result = multiplication(float(string1[0]), float(string1[1]))

elif string1[2] == "/":

result = division(float(string1[0]), float(string1[1]))

return result

# This function returns the results of input values in addition, subtraction, multiplication and division

def allInOne(self):

add = self.a + self.b

subtract = self.a - self.b

multiply = self.a * self.b

divide = self.a / self.b

print('res is dictionary', {"add": add, "sub": subtract, "mult": multiply, "div": divide})

return{"add": add, "sub": subtract, "mult": multiply, "div": divide}

import Mylib

def main():

# Menu list of math operations for use

menuList = ["1) Addition", "2) Subtraction", "3) Multiplication", "4) Division", "5) Scalc", "6) All in one"]

while True:

try:

print("Please enter any math operation: ")

for n in menuList:

print(n)

choice = int(input("Please input your selection: "))

# Users input against available options in menu list.

if choice > 6 or choice < 1:

print("You did not enter a valid selection , please try again")

break

except ValueError:

print("Zero values are not allowed; please try again!'")

break

# Users input value within given range

print("Please enter a value for low & high range between 1 & 100")

lowRange = int(input("Enter your low range ---> "))

if lowRange < 1 or lowRange > 100:

print("Please make sure to enter a value range of 1 to 100")

break

highRange = int(input("Enter your high range ---> "))

if highRange < 1 or highRange > 100:

print("Please make sure to enter a value range of 1 to 100")

break

firstNum=int(input("Enter first number: "))

secondNum=int(input("Enter second number: "))

obj=cal(firstNum,secondNum)

# Users input value within the given ranges

while True:

if firstNum < lowRange or firstNum > highRange:

print("You did not enter a valid number, please try again!")

break

if secondNum < lowRange or secondNum > highRange:

print("You did not enter a valid number, please try again!")

break

if choice == 1:

print(firstNum, '+', secondNum, '=', obj.add(firstNum, secondNum))

elif choice == 2:

print(firstNum, '-', secondNum, '=', obj.sub(firstNum, secondNum))

elif choice == 3:

print(firstNum, '*', secondNum, '=', obj.mult(firstNum, secondNum))

elif choice == 4:

print(firstNum, '/', secondNum, '=', obj.div(firstNum, secondNum))

elif choice == 5:

print("The Result of ",firstNum,"+",secondNum,"=", Mylib.add(firstNum, secondNum))

print("The Result of ",firstNum,"-",secondNum,"=", Mylib.sub(firstNum, secondNum))

print("The Result of ",firstNum,"*",secondNum,"=", Mylib.mult(firstNum, secondNum))

print("the result of:",firstNum,"/",secondNum,"=", Mylib.div(firstNum, secondNum))

elif choice == 6:

res = Mylib.allInOne(firstNum, secondNum)

print(firstNum, " + ", secondNum, " = ", res["add"])

print(firstNum, " - ", secondNum, " = ", res["sub"])

print(firstNum, " * ", secondNum, " = ", res["mult"])

print(firstNum, " / ", secondNum, " = ", res["div"])

while True:

reCalculate = input("Please enter 1 to re-run or 2 to exit the program: ")

if reCalculate == '1':

print()

main()

else:

print("Thanks for using calculator! ")

main()

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 Programming Questions!