-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathElse_and_finaly.py
45 lines (35 loc) · 1.01 KB
/
Else_and_finaly.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Else with try
class ZeroDenominatorError(ZeroDivisionError): # ZeroDivisionError is parent class of user defined error
pass
while 1:
try:
n=input('Enter numerator')
num=int(n)
n=input('Enter denominator')
denom=int(n)
if denom==0:
raise ZeroDenominatorError('Denominator should not be zero')
except(ZeroDivisionError):
print('Denominator is always greater then zeero')
else:
value = (num / denom)
print(value)
break
class ZeroDenominatorError(ZeroDivisionError):
pass
while True:
try:
n=input('Enter numerator')
num=int(n)
n=input('Enter denominator')
denom=int(n)
if denom==0:
raise ZeroDenominatorError('Denominator should not be zero')
except(ZeroDivisionError):
print('Denominator is always greater then zeero')
else:
value = (num / denom)
print(value)
break
finally:
print('Exception raised may or may not be')