-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator.py
70 lines (56 loc) · 1.88 KB
/
Calculator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class Calculator:
"""
This class solves basic mathematical operations:
addition, subtraction, multiplication, and division.
"""
def __init__(self):
"""
This is the constructor for the Calculator class. It does not require any arguments.
"""
pass
def add(self, a, b):
"""
This method adds two numbers and returns the sum of numbers.
Args:
a (float): The first number to be added.
b (float): The second number to be added.
Returns:
float: The sum of a and b.
"""
return a + b
def subtract(self, a, b):
"""
This method subtracts two numbers and returns the difference of numbers.
Args:
a (float): The first number from which the second number will be subtracted.
b (float): The second number to be subtracted from the first number.
Returns:
float: The difference of a and b.
"""
return a - b
def multiply(self, a, b):
"""
This method multiplies two numbers and returns the product of numbers.
Args:
a (float): The first number to be multiplied.
b (float): The second number to be multiplied.
Returns:
float: The product of a and b.
"""
return a * b
def divide(self, a, b):
"""
This method divides two numbers and returns the quotient of numbers.
Args:
a (float): The dividend (number to be divided).
b (float): The divisor (number by which to divide).
Raises:
CalculatorError: If the divisor (b) is zero.
Returns:
float: The quotient of a and b.
"""
if b == 0:
raise ZeroDivisionError("Division by zero")
return a / b
class CalculatorError(Exception):
pass