-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcalculator.py
64 lines (49 loc) · 1.89 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
## calculator.py
class Calculator:
def add(self, number1: float, number2: float) -> float:
"""Add two numbers and return the result.
Args:
number1 (float): The first number.
number2 (float): The second number.
Returns:
float: The sum of the two numbers.
"""
return number1 + number2
def subtract(self, number1: float, number2: float) -> float:
"""Subtract the second number from the first and return the result.
Args:
number1 (float): The first number.
number2 (float): The second number.
Returns:
float: The difference between the two numbers.
"""
return number1 - number2
def multiply(self, number1: float, number2: float) -> float:
"""Multiply two numbers and return the result.
Args:
number1 (float): The first number.
number2 (float): The second number.
Returns:
float: The product of the two numbers.
"""
return number1 * number2
def divide(self, number1: float, number2: float) -> float:
"""Divide the first number by the second and return the result.
Args:
number1 (float): The first number.
number2 (float): The second number.
Returns:
float: The quotient of the two numbers.
Raises:
ValueError: If the second number is zero.
"""
if number2 == 0:
return 'Error: Cannot divide by zero.'
return number1 / number2
def reset(self) -> None:
"""Reset the calculator to its initial state.
This method is currently a placeholder as the Calculator class
does not maintain any internal state. However, it's included for
future extensibility.
"""
pass # No state to reset; method is here for potential future use.