Skip to content

Commit

Permalink
Updated assert_exceptions.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Babatunde13 committed Apr 22, 2020
1 parent 257cad9 commit 1e1b1d2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion week4/codes/assert_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,22 @@ def add(a: int, b: int) -> int:
return f"Function takes two arguments, I'll assume that your other argument is 0. sum of {a} and 0 is {a}"
else:
return f"Sum of {a} and {b} is {c}"
def add(a: int, b: int) -> int:
try:
a = float(a)
b = float(b)
c = a + b
c = round(c, 3)
except TypeError:
return "Function takes two arguments, I'll assume that your other argument is 0. sum of {a} and 0 is {a}"
except ValueError:
return f"Input should be integer"
else:
return f"Sum of {a} and {b} is {c}"

print(add(1, 2))
print(add(4.6, 7.8))
print(add(4.56))
print(add(4.56, [1]))



0 comments on commit 1e1b1d2

Please sign in to comment.