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 652afc5 commit 81d09cb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions week4/codes/assert_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,16 @@ def add(a: int, b: int) -> int:
print(add(4.56, [1])) # Input should be integer now
print(add('a', 'b')) # Input should be integer

def sub(a, b):
try:
c = a - b
except Exception as e: # e is the error message.
return "Invalid Input. "+str(e).capitalize()
else:
return c

print(sub(1, 2)) # -1
print(sub(1, 'a')) # Invalid Input. Unsupported operand type(s) for +: 'int' and 'str'



0 comments on commit 81d09cb

Please sign in to comment.