-
Notifications
You must be signed in to change notification settings - Fork 33
/
helper.py
47 lines (34 loc) · 1.12 KB
/
helper.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
# create helper functions for calculations
def perform_calculation(value1: float, value2: float, operation: str) -> float:
"""
Perform a mathematical operation on two values.
Parameters:
value1 (float): The first value.
value2 (float): The second value.
operation (str): The operation to perform. Can be 'add', 'subtract', 'divide', or 'multiply'.
Returns:
float: The result of the operation.
Raises:
ZeroDivisionError: If attempting to divide by zero.
"""
if operation == 'add':
result = value1 + value2
elif operation == 'subtract':
result = value1 - value2
elif operation == 'divide':
result = value1 / value2
else:
result = value1 * value2
return result
def convert_to_float(value: str) -> float:
"""
Convert string to floating point number.
Parameters:
value (str): The value to convert.
Returns:
float: The converted float value of input value.
Raises:
ValueError: If value cannot be converted to a float.
"""
float_value = float(value)
return float_value