-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexception_handling.py
More file actions
143 lines (128 loc) · 4.02 KB
/
exception_handling.py
File metadata and controls
143 lines (128 loc) · 4.02 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
'''exception handling'''
# num1=int(input("Enter the first number :"))
# num2=int(input("Enter the second number :"))
# print(num1/num2)
#Exception => is the way to control the error during the execution
# Division by zero
# File not found
# Null or None reference access
# Network timeouts
# try:
# num1=int(input("Enter the first number :"))
# num2=int(input("Enter the second number :"))
# print(num1/num2)
# except Exception as e:
# print(e)
# try:
# num1=int(input("Enter the first number :"))
# num2=int(input("Enter the second number :"))
# print(num1/num2)
# except ZeroDivisionError:
# num1=int(input("Enter the first number :"))
# num2=int(input("Enter the second number :"))
# print(num1/num2)
# except Exception as e:
# print("teji")
# else:
# print("no error occur")
# try:
# num1=int(input("Enter the first number :"))
# num2=int(input("Enter the second number :"))
# print(num1/num2)
# except Exception as e:
# print("teji")
# else:
# print("no error occur")
# finally:
# print("alwayes execute")
''' loop'''
# try:
# num1=int(input("Enter the first number :"))
# num2=int(input("Enter the second number :"))
# print(num1/num2)
# except ZeroDivisionError:
# while True:
# try:
# num1=int(input("Enter the first number :"))
# num2=int(input("Enter the second number :"))
# print(num1/num2)
# except ZeroDivisionError:
# True
# else:
# break
"""another method"""
# while True:
# try:
# num1=int(input("Enter the first number :"))
# num2=int(input("Enter the second number :"))
# print(num1/num2)
# except ZeroDivisionError:
# True
# else:
# break
# while True:
# try:
# num1=int(input("Enter the first number :"))
# num2=int(input("Enter the second number :"))
# print(num1/num2)
# break
# except ZeroDivisionError:
# True
# except ValueError:
# True
"""use raise to create exception """
# try:
# age=int(input("Enter age: "))
# if age<18:
# raise Exception ("age error occured") #intentionally generate (raise) an exception when we want to
# else:
# print("eligible for vote")
# except Exception as e:
# print("error-->",e)
# """ """
# try:
# age=int(input("Enter age: "))
# if age<18:
# raise Exception ("age error occured") #intentionally generate (raise) an exception when we want to
# elif age==18:
# raise Exception ("age=18 ")
# else:
# print("eligible for vote")
# except Exception as e:
# print("error-->",e)
# """ use this way to short the code"""
# try:
# age=int(input("Enter age: "))
# if age<18:
# raise Exception ("age error occured") #intentionally generate (raise) an exception when we want to
# print("eligible for vote")
# except Exception as e:
# print("error-->",e)
"""create a ATM program through Exception handling """
# print("welcome to atm")
# amount=1000
# A=input("press the key(withdrawal,deposite,check balance)")
# if A=="withdrawal":
# E=int(input("Enter amount: "))
# try:
# if E<=amount:
# amount=amount-E
# print("secussfully withdrawal renmaining amount=",amount)
# else :
# raise Exception ("Enter valid amount")
# except Exception as e:
# print(e)
# elif A=="deposite":
# D=int(input("Enter deposite amount: " ))
# try:
# if D<=0:
# raise Exception ("plz Enter valid input")
# else:
# amount=D+amount
# print("your new balance is : ",amount)
# except Exception as e:
# print(e)
# elif A=="check balance":
# print(amount)
# else:
# print("plz press valid key")