-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
40 lines (30 loc) · 1008 Bytes
/
Copy pathapp.py
File metadata and controls
40 lines (30 loc) · 1008 Bytes
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
# app.py — Basic Calculator
# This file is used across all 4 Claude Code setup demos (Lecture 6.1)
def add(a: float, b: float) -> float:
"""Return the sum of a and b."""
return a + b
def subtract(a: float, b: float) -> float:
"""Return the result of subtracting b from a."""
return a - b
def multiply(a: float, b: float) -> float:
"""Return the product of a and b."""
return a * b
def divide(a: float, b: float) -> float:
"""Return the result of dividing a by b.
Raises:
ValueError: If b is zero.
"""
if b == 0:
raise ValueError("Cannot divide by zero.")
return a / b
if __name__ == "__main__":
print("Basic Calculator")
print("----------------")
print(f"10 + 5 = {add(10, 5)}")
print(f"10 - 5 = {subtract(10, 5)}")
print(f"10 * 5 = {multiply(10, 5)}")
print(f"10 / 5 = {divide(10, 5)}")
try:
print(f"10 / 0 = {divide(10, 0)}")
except ValueError as e:
print(f"10 / 0 = Error: {e}")