← Back to challenges

Simple OOP Calculator

PythonHardclassesmathnumbers

Instructions

Create methods for the Calculator class that can do the following:

  • Add two numbers.
  • Subtract two numbers.
  • Multiply two numbers.
  • Divide two numbers.

Examples

calculator = Calculator()

calculator.add(10, 5) ➞ 15

calculator.subtract(10, 5) ➞ 5

calculator.multiply(10, 5) ➞ 50

calculator.divide(10, 5) ➞ 2

Notes

  • The methods should return the result of the calculation.
  • Don't worry about needing to handle division by zero errors.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Unusual Subtraction