Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Purposely written incorrectly, so that we can see the Call Stack
- def factorial(x):
- if x > 1:
- return x * factorial(x-1)
- else:
- return 5 / 0
- #Exception Handling for TypeError and ValueError
- #TypeError = Value is not an int
- #ValueError = Value is Negative
- def add_two_numbers(x,y):
- if not isinstance(x, int) or not isinstance(y,int):
- raise TypeError()
- if x < 0 or y < 0:
- raise ValueError()
- else:
- return x + y
- def addPositives(x,y):
- if x < 1 or y < 1:
- raise TypeError()
- return x + y
- # x = addPositives(3, -2)
- # except:
- # print("use positive values dummy")
- #Add Positives with Assertion
- def addPositive(x, y):
- assert x > 0
- assert y > 0
- return x + y
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement