Repository navigation
Expand file tree
/
Copy pathAdd_List.py
More file actions
54 lines (47 loc) · 1.51 KB
/
Copy pathAdd_List.py
File metadata and controls
54 lines (47 loc) · 1.51 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
class NegativeValue(Exception):
def __init__(self, input, message = ("Enter a positive")):
self.input = input
self.message = message
super().__init__(self.message)
class WrongInput(Exception):
pass
while True:
list = []
try:
count = input("Enter the range of the list: ")
if (int(count) < 0):
raise NegativeValue(input)
elif (count.isalpha()):
raise WrongInput
else:
for x in range(1, int(count) + 1):
try:
data = input("Enter the data: ")
if (int(data) < 0):
raise NegativeValue(input)
elif (data.isalpha()):
raise WrongInput
else:
list.append(data)
except NegativeValue:
print("This value is negative")
continue
except WrongInput:
print("This value contains alphabet")
continue
except ValueError:
print("This value contains alphabet")
continue
print(list)
list.sort()
print(list)
break
except NegativeValue:
print("This value is negative")
continue
except WrongInput:
print("This value contains alphabet")
continue
except ValueError:
print("This value contains alphabet")
continue