0

I'm learning some python OOP and I'm trying to make this little calculator thing and this is the code:

code

class Math():

    def add(self, a, b):
        return a + b

    def subtract(self, a, b):
        return a - b

    def divide(self, a, b):
        try:
            return a / b
        except ZeroDivisionError:
            print("Error")

math = Math()

while True:

    operation = input("Enter operation: ")

    if operation.lower() == '+' or 'add':
        a = int(input("Enter the first number: "))
        b = int(input("Enter the second number: "))
        print(f"{a} + {b} = {math.add(a, b)}\n")

    if operation.lower() == '-' or 'subtract':
        a = int(input("Enter the first number: "))
        b = int(input("Enter the second number: "))
        print(f"{a} - {b} = {math.subtract(a, b)}\n")

    if operation.lower() == '/' or 'divide':
        a = int(input("Enter the first number: "))
        b = int(input("Enter the second number: "))
        print(f"{a} / {b} = {math.divide(a, b)}\n")

doesn't matter what operation I add it always does + then - then /, I do not know why this is happening can someone help?

yoda
  • 35
  • 3

0 Answers0