-1

I'm very new to python 3 (and programming in general), and I'm having some issues understanding why this is happening.

class calculator:

    def addition(x, y):
        added = x + y
        print(added)

    def subtraction(x, y):
        sub = x - y
        print(sub)

    def multiplication(x, y):
        mult = x * y
        print(mult)

    def division(x, y):
        div = x / y
        print(div)

calc = calculator()

calc.multiplication(3,5)

I'm getting the issue this issue:

Traceback (most recent call last):
File "/Users/JordanM/Desktop/PythonFiles/Calculator.py", line 20, in <module>
calc.multiplication(3,5)

TypeError: multiplication() takes exactly 2 arguments (3 given)

Can anyone give some insight as to why this is happening? Is there a better way to do this that works?

1 Answers1

0

You need to add self to all the functions that is consumed by instances . Its like this in javascript.It points to current instance.

   def addition(self,x, y):
        added = x + y
        print(added)
Vidya
  • 7,717
  • 12
  • 48
  • 75