forked from GeekBrainsTutorial/Python_lessons_basic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
39 lines (28 loc) · 779 Bytes
/
Copy pathexceptions.py
File metadata and controls
39 lines (28 loc) · 779 Bytes
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
# coding: utf-8
import sys
class BadNumber(Exception):
def __init__(self, x):
self.x = x
def __str__(self):
return '! **** Нехорошее число: {} ****'.format(self.x)
f = open('numbers.txt')
for line in f:
try:
x = int(line.strip())
if x == 13:
raise BadNumber(x)
except ValueError:
print('Ошибка перевода числа в int')
sys.exit(13)
except BadNumber as bn:
print(bn)
else:
print(x)
try:
y = 1000 / x
except ZeroDivisionError as z:
print(z)
else:
print(y)
finally:
print('Выходим из блока try')