-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate.py
43 lines (34 loc) · 1.44 KB
/
calculate.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
def calculate_total(a, b):
"""Calculate the sum of two numbers."""
return a + b
if __name__ == "__main__":
print("The total is:", calculate_total(10, 5))
def calculate_difference(a, b):
"""Calculate the difference between two numbers."""
return a - b
def calculate_total(a, b):
"""Calculate the sum of two numbers with basic error checking."""
if not isinstance(a, (int, float)) or not isinstance(b, (int, float)):
raise ValueError("Both arguments must be numbers")
return a + b
if __name__ == "__main__":
print(f"The total of 10 and 5 is: {calculate_total(10, 5)}")
def calculate_total(a, b):
"""Calculate the sum of two numbers, with intentional rounding error."""
return round(a + b, 1) # Introduces minor rounding
def calculate_product(a, b):
"""Calculate the product of two numbers."""
return a * b
def calculate_total(a, b):
"""Calculate the total of two numbers, with an intentional bug."""
return a * b # Bug remains
def calculate_division(a, b):
"""Calculate the division of two numbers."""
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
if __name__ == "__main__":
print(f"The total of 10 and 5 is: {calculate_total(10, 5)}")
print(f"The difference of 10 and 5 is: {calculate_difference(10, 5)}")
print(f"The product of 10 and 5 is: {calculate_product(10, 5)}")
print(f"The division of 10 by 5 is: {calculate_division(10, 5)}")