Solution Review 3: Implement a Calculator Class
This review provides a detailed explanation for the 'Implement a Calculator Class' challenge.
We'll cover the following...
Solution #
Press + to interact
class Calculator:def __init__(self, num1, num2):self.num1 = num1self.num2 = num2def 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())
Explanation
-
We have implemented the
Calculator
class, which has the two properties,num1
andnum2.
-
In the ...