-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathassignment13_Exception.py
More file actions
87 lines (63 loc) · 1.34 KB
/
assignment13_Exception.py
File metadata and controls
87 lines (63 loc) · 1.34 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
print("question 01")
a=3
try:
if a<4:
a=a/(a-3)
print(a)
except Exception as e:
print(e)
#Exception name:division by zero
print("question 02")
l=[1,2,3]
try:
print(l[3])
except Exception as e:
print(e)
#Exception name:list index out of range
print("question no 03")
try:
raise NameError("Hi there") # Raise Error
except NameError:
print("An exception")
#exception is raised exception name is:NameError: Hi there
print("question 04")
def AbyB(a,b):
try:
c = ((a+b)/(a-b))
except ZeroDivisionError:
print("a/b result in 0")
else:
print(c)
# Driver program to test above function
AbyB(2.0, 3.0)
AbyB(3.0, 3.0)
#output
#-5.0
#a/b result in 0
print("question no 05")
#import rahul
#it genrate import exception ModuleNotFoundError: No module named 'rahul'
m=int(input("enter any string:"))
try:
print(m)
except Exception as e:
print(e)
#ValueError: invalid literal for int() with base 10: 'rahul'
l=[1,2,3]
try:
print(l[3])
except Exception as e:
print(e)
#list index out of range
print("question no 06")
class AgeTooSmallError(Exception):
pass
try:
while True:
age = int(input("enter any age:"))
if age<18:
print("age is less than 18: ",age)
else:
raise AgeTooSmallError("age is above 18")
except AgeTooSmallError as e:
print(e)