25 lines
791 B
Python
25 lines
791 B
Python
|
def customInput(msg, interval):
|
||
|
while True:
|
||
|
try:
|
||
|
answer = int(input(msg))
|
||
|
assert answer in range(*interval)
|
||
|
return answer
|
||
|
except (AssertionError, ValueError):
|
||
|
print('You have to gie a value in the interval [1,10]. Try again')
|
||
|
|
||
|
def do_user_like(items):
|
||
|
print('On a scale of 1 to 10 where 10 is the highest, how much do you like:')
|
||
|
return [(item, customInput(f'{item}? ', (1,11))) for item in items]
|
||
|
|
||
|
|
||
|
def get_prioritized_list(lst):
|
||
|
return sorted(lst, key=lambda tuple: (tuple[1], tuple[0]), reverse=True)
|
||
|
|
||
|
def what_user_likes_best(items, num):
|
||
|
sortedList = get_prioritized_list(do_user_like(items))
|
||
|
print(f'Your top {num} are')
|
||
|
for i in range(num):
|
||
|
print(f'{i+1}. {sortedList[i][0]}')
|
||
|
|
||
|
|
||
|
x = what_user_likes_best(['dof', 'fas', 'be', 'aa'], 2)
|