-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpicker.py
36 lines (33 loc) · 1.07 KB
/
picker.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
class SetupPicker: # TODO implement some go back functionality
def __init__(self, items, number):
self.items = items
self.number = number
self.pick()
def _get_valid_input(self, num, picked):
inp = input("Item %s: " % num)
val = int(inp)
if val < 0 or val >= len(self.items) or val in picked:
raise ValueError
else:
return val
def pick(self):
picked = set()
print("Pick %s items: " % self.number)
for idx, n in enumerate(self.items):
print("%s: %s" % (idx, n))
game_list = []
def get_single(num):
try:
picked_idx = self._get_valid_input(num, picked)
except ValueError:
print("Invalid Input. Try again.\n")
return get_single(num)
else:
return picked_idx
i = 0
while i < self.number:
val = get_single(i)
picked.add(val)
game_list.append(self.items[val])
i += 1
return game_list