Implementation of addition of integer Examples: >>> add(3, 5) 8 >>> add(13, 5) 18 >>> add(-7, 2) -5 >>> add(0, -7) -7 >>> add(-321, 0) -321
(first: int, second: int)
| 7 | |
| 8 | |
| 9 | def add(first: int, second: int) -> int: |
| 10 | """ |
| 11 | Implementation of addition of integer |
| 12 | |
| 13 | Examples: |
| 14 | >>> add(3, 5) |
| 15 | 8 |
| 16 | >>> add(13, 5) |
| 17 | 18 |
| 18 | >>> add(-7, 2) |
| 19 | -5 |
| 20 | >>> add(0, -7) |
| 21 | -7 |
| 22 | >>> add(-321, 0) |
| 23 | -321 |
| 24 | """ |
| 25 | while second != 0: |
| 26 | c = first & second |
| 27 | first ^= second |
| 28 | second = c << 1 |
| 29 | return first |
| 30 | |
| 31 | |
| 32 | if __name__ == "__main__": |
no outgoing calls
no test coverage detected