forked from psounis/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise03.py
More file actions
56 lines (45 loc) · 1.69 KB
/
exercise03.py
File metadata and controls
56 lines (45 loc) · 1.69 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
class ValueTooSmallError(Exception):
def __init__(self, message):
self.message = message
class ValueTooLargeError(Exception):
def __init__(self, message):
self.message = message
class NotMultipleOfFiveError(Exception):
def __init__(self, val):
self.val = val
def __str__(self):
return f"{self.val} is not multiple of 5"
def get_integer_con():
while True:
try:
user_input = input("Give integer: ")
if user_input[0] == "-":
st = user_input[1:]
if st == "":
raise ValueError("No digits entered!")
elif not st.isdigit():
raise ValueError("Wrong Input. Only digits please!")
else:
raise ValueTooSmallError("Value must be >= 100.")
else:
st = user_input
if st == "":
raise ValueError("No digits entered!")
elif not st.isdigit():
raise ValueError("Wrong Input. Only digits please!")
x = int(st)
if x < 100:
raise ValueTooSmallError("Value must be >= 100.")
elif x > 200:
raise ValueTooLargeError("Value must be <= 200.")
elif x % 5 != 0:
raise NotMultipleOfFiveError(x)
except (ValueTooSmallError, ValueTooLargeError, NotMultipleOfFiveError) as e:
print(e)
except ValueError as v:
print(v)
except Exception as e:
print(e)
else:
return x
print(get_integer_con())