-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0029_buy_computer.py
More file actions
31 lines (28 loc) · 1.06 KB
/
0029_buy_computer.py
File metadata and controls
31 lines (28 loc) · 1.06 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
available_parts = ['computer',
'monitor',
'keyboard',
'mouse',
'HDMI cable',
'dvd drive'
]
current_choice = '-'
computer_parts = []
valid_choices = [str(i) for i in range(1, len(available_parts) + 1)]
print(valid_choices)
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:
computer_parts.remove(chosen_part)
print('Removing {}'.format(current_choice))
else:
computer_parts.append(available_parts[int(current_choice) - 1])
print('Adding {}'.format(current_choice))
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}:\t{1}'.format(number + 1, part))
current_choice = input()
print(computer_parts)