-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.py
57 lines (43 loc) · 1.18 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
def add(x: float, y: float) -> float:
"""
Adds two floats.
Args:
x (float): The first number.
y (float): The second number.
Returns:
float: The sum of the two numbers.
"""
return x + y
def subtract(x: float, y: float) -> float:
"""
Subtracts one float from another.
Args:
x (float): The first number.
y (float): The second number.
Returns:
float: The difference of the two numbers.
"""
return x - y
def multiply(x: float, y: float) -> float:
"""
Multiplies two floats.
Args:
x (float): The first number.
y (float): The second number.
Returns:
float: The product of the two numbers.
"""
return x * y
def divide(x: float, y: float) -> float | str:
"""
Divides one float by another. If the divisor is zero, returns an error message instead.
Args:
x (float): The dividend.
y (float): The divisor.
Returns:
float | str: Either the result of the division or a division-by-zero error message.
"""
if y == 0 or x == 0:
return "Error: Division by zero is not allowed"
else:
return x / y