Skip to content

Commit 0f5d1e4

Browse files
authored
Create add function to sum two integers
Implement add function with type hints and input validation.
1 parent 841e947 commit 0f5d1e4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

math/add.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def add(a: int, b: int) -> int:
2+
"""
3+
Return sum of two integers
4+
5+
>>> add(2, 3)
6+
5
7+
>>> add(-1, 1)
8+
0
9+
"""
10+
if not isinstance(a, int) or not isinstance(b, int):
11+
raise ValueError("Inputs must be integers")
12+
return a + b

0 commit comments

Comments
 (0)