forked from ShadabImran07/python-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
improving.py
35 lines (32 loc) · 1.18 KB
/
improving.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
available_parts = ["computer",
"monitor",
"keyboard",
"mouse",
"hdmi cable",
"dvd drive"
]
#valid_choices = [str(i) for i in range(1, len(available_parts) +1)]
valid_choices = []
for i in range(1, len(available_parts) + 1):
valid_choices.append(str(i))
print(valid_choices)
current_choice = "-"
computer_parts = [] # create an empty list
while current_choice != '0':
if current_choice in valid_choices:
index = int(current_choice) - 1
chosen_part = available_parts[index]
if chosen_part in computer_parts:
# it's already in, so remove it
print("Removing {}".format(current_choice))
computer_parts.remove(chosen_part)
else:
print("Adding {}".format(current_choice))
computer_parts.append(chosen_part)
print("Your list now contains: {}".format(computer_parts))
else:
print("Please add options from the list below:")
for number, part in enumerate(available_parts):
print("{0}: {1}".format(number + 1, part))
current_choice = input()
print(computer_parts)