educative.io

Calculator takes no arguments?

Dear Sir,

While I execute the codes, it responsed the error as attached. I dont know where the error is.


Course: Learn Object-Oriented Programming in Python - Learn Interactively
Lesson: Solution Review 3: Implement a Calculator Class - Learn Object-Oriented Programming in Python

My name is Shahrukh Naeem. I hope everything is going well with you. Thank you for reaching out about this. I will try my best to answer your query!

I haven’t faced any errors on my side. I think you missed something, try the following complete code and hopefully, you will not face any errors:

class Calculator:
    def __init__(self, num1, num2):
        self.num1 = num1
        self.num2 = num2
    def add(self):
        return (self.num2 + self.num1)
    def subtract(self):
        return (self.num2 - self.num1)
    def multiply(self):
        return (self.num2 * self.num1)
    def divide(self):
        return (self.num2 / self.num1)
demo1 = Calculator(10, 94)
print("Addition:", demo1.add())
print("Subtraction:", demo1.subtract())
print("Mutliplication:", demo1.multiply())
print("Division:", demo1.divide())

For reference, I have attached the screenshot here:

I hope that this guide is helpful. Remember that I am always available via message to help you with any difficulty you might encounter.

Regards,

Happy Learning :slight_smile: