-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbite_10.py
More file actions
22 lines (16 loc) · 694 Bytes
/
bite_10.py
File metadata and controls
22 lines (16 loc) · 694 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'''In this Bite you'll learn to catch and raise Python exceptions.
Write a simple division function meeting the following requirements:
1. When the denominator is zero, catch the corresponding exception and return zero.
2. When the numerator or denominator have an invalid type reraise the corresponding exception.
3. If the result of the division is negative raise a ValueError.'''
# Online Python - IDE, Editor, Compiler, Interpreter
def positive_divide(numerator, denominator):
if denominator == 0:
return 0
try:
result = numerator / denominator
if result < 0:
raise ValueError()
except TypeError as e:
raise e
return result