-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path017.usingLists.py
More file actions
36 lines (31 loc) · 1.16 KB
/
017.usingLists.py
File metadata and controls
36 lines (31 loc) · 1.16 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
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 = [] # empty list
while current_choice != '0':
if current_choice in valid_choices:
#print("Adding {}".format(current_choice))
index = int(current_choice) - 1
chosen_part = available_parts[index]
if chosen_part in computer_parts:
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 option from the list below:")
for number,part in enumerate(available_parts):
print("{0}: {1}".format(number + 1,part))
current_choice= input()
print(computer_parts)