-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exception.py
94 lines (77 loc) · 1.59 KB
/
Exception.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
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
85
86
87
88
89
90
91
92
93
94
'''try:
a = int(input("Enter a:"))
b = int(input("Enter b:"))
c = a/b;
print("a/b = ",c)
except Exception:
print("can't divide by zero")
else:
print("Hi I am else block") '''
'''
try:
fileptr = open("file.txt","r")
except IOError:
print("File not found")
else:
print("The file opened successfully")
fileptr.close() '''
'''
try:
a=10/0;
except (ArithmeticError,IOError,SyntaxError):
print("Arithmetic Exception")
else:
print("Successfully Done")
'''
'''
try:
fileptr = open("file.txt","r")
try:
fileptr.write("Hi I am good")
finally:
fileptr.close()
print("file closed")
except:
print("Error")
'''
'''
try:
age = int(input("Enter the age: "))
if age<18:
raise ValueError;
else:
print("the age is valid")
except ValueError:
print("The age is not valid")
'''
'''
try:
a = int(input("Enter a: "))
b = int(input("Enter b: "))
if b is 0:
raise ArithmeticError;
else:
print("a/b = ",a/b)
except ArithmeticError:
print("The value of b can't be 0")
'''
'''
class computer:
def __init__(self,cpu,ram):
self.cpu=cpu
self.ram=ram
def config(self):
print(self.ram,"",self.cpu)
com1 = computer("i5",16)
com2 = computer("amd",8)
com1.config()
com2.config()
'''
def __init__(self,age):
try:
if age<18:
raise ValueError
else:
print("valid age")
except ValueError:
print("invalid age")