-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_operations_input.py
64 lines (52 loc) · 1.97 KB
/
list_operations_input.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
# This program will ask for numbers to add to a list, and then delete the repeated ones.
# Finally, it will show the result sorted.
#(Just one way of doing it)
# I put the lists here for clarity.
# The end is just as a flag that is going to determine if we finish the program before the end point.
myList= []
uniqueList= []
repeatedValues=[]
end= True
try:
elements = int(input("How many numbers do you want to insert?: "))
except:
try:
elements = int(input("Not letters, in numbers please: "))
except:
end= False
print("Don't have time now for this...")
if end:
counter= 0
for i in range(elements):
if counter<=1:
try:
value= float(input("Insert an integer, please: "))
myList.insert(0, int(value))
except:
repeating= True
while repeating:
if counter<=1:
try:
value= float(input("I was distracted... sorry. Can you repeat it, please? "))
repeating = False
myList.insert(0, int(value))
except:
print("I'm confused today...")
counter += 1
else:
repeating = False
print("Why don't we try it later?")
end= False
if end:
print("\nSummarizing:", end="\n\n")
print("\tElements in your list:\n\t", myList, end="\n\n")
for i in myList:
if i not in uniqueList:
uniqueList.insert(0, i)
else:
repeatedValues.append(i)
uniqueList.sort()
myList= uniqueList[:] # check the slice that let us copy all the values easily
print("\tThe distinct elements in the list are: \n\t",myList, end="\n\n")
print("\tThe repeated ones: \n\t",repeatedValues, end="\n\n")
print("That's all! Thanks!")