Answer to Question #267123 in Python for Matteo Villamor

Question #267123

import math

print("MAIN MENU")

print("1. Addition")

print("2. Subtraction")

print("3. Multiplication")

print("4. Division")

print("5. Modulus")

print("6. Exponentiation")

print("7. Absolute value")

print("8. Factorial")

print("9. Logarithm")

print("10. Round Up")

print("11. Round Down")

print("12. Square Root")

print("13. Trigonometric Functions")

print("14. Inverse Trigonometric Functions")

print("15. Hyperbolic Functions")

print("16. Inverse Hyperbolic Functions")

print("")

print("NOTE: If you're performing operations in the 1-6 range, don't make the second number zero." )

print()



op = int(input("Enter the operation you want to perform : "))



Question:

1. In this program, you are going to create with getter and setter.


1
Expert's answer
2021-11-16T13:50:50-0500
import math
class Calculator:
    
    
    
    def menu(self):
        print("MAIN MENU")
        print("1. Addition")
        print("2. Subtraction")
        print("3. Multiplication")
        print("4. Division")
        print("5. Modulus")
        print("6. Exponentiation")
        print("7. Absolute value")
        print("8. Factorial")
        print("9. Logarithm")
        print("10. Round Up")
        print("11. Round Down")
        print("12. Square Root")
        print("13. Trigonometric Functions")
        print("14. Inverse Trigonometric Functions")
        print("15. Hyperbolic Functions")
        print("16. Inverse Hyperbolic Functions")
        print("")
        print("NOTE: If you're performing operations in the 1-6 range, don't make the second number zero." )
        print()
    def __init__(self,operator,firstOperand,secondOperand ):
        self.menu()
        self.operator =int(input("Enter operator: ")) 
        self.firstOperand = int(input("Enter the first operand: "))
        self.secondOperand = int(input("Enter the second operand:  "))
    
    #Getters and Setters
    def getFirstOperand(self):
        return self.firstOperand
    def getSecondOperand(self):
        return self.secondOperand
    def setSecond(self, operand):
        self.secondOperand = operand
    def setFirst(self, operand):
        self.firstOperand = operand
    def setOperand(self, op):
        self.operator = op
    def calculate(self):
        if self.operator == 0:
            print("Thank you for using our calculator!")
        elif self.operator == 1:
            print("The sum is "+ str((self.firstOperand + self.secondOperand)))
        elif self.operator == 2:
            print("The difference is "+ str(abs(self.firstOperand - self.secondOperand)))
        elif self.operator == 3:
             print("The quotent is "+ str((self.firstOperand / self.secondOperand)))
        elif self.operator == 4:
             print("The Product is "+ str((self.firstOperand * self.secondOperand)))
        elif self.operator == 5:
             print("The modulus is "+ str((self.firstOperand % self.secondOperand)))
        elif self.operator == 6:
             print("The Exponentiation is "+ str((Math.pow(self.firstOperand,self.secondOperand) )))
op = " "
secondOperand =" "
firstOperand = ""
cala = Calculator(op,firstOperand,secondOperand )




cala.calculate()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS