Через флаги:
violator_songs = [
['World in My Eyes', 4.86],
['Sweetest Perfection', 4.43],
['Personal Jesus', 4.56],
['Halo', 4.90],
['Waiting for the Night', 6.07],
['Enjoy the Silence', 4.20],
['Policy of Truth', 4.76],
['Blue Dress', 4.29],
['Clean', 5.83]
]
li = []
special_list = []
qty = int(input('Сколько песен выбрать? '))
print()
count = 1
ok = True
while ok:
for _ in range(qty):
if ok:
song = input('Введите название ' + str(count) + ' песни: ')
for elem in violator_songs:
li.extend(elem)
if song not in li:
print('Ошибка. Такой песни в плейлисте нет!')
ok = False
break
else:
special_list.append(song)
count += 1
summ = 0
for i_time in violator_songs:
if i_time[0] in special_list:
summ += i_time[1]
print('\nОбщее время звучания песен:', float(round(summ, 2)))
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 А (если в двоичной системе цифра 16, то в шестнадцатеричной 10, если 17, то 11 и так далее)
Через флаги:
violator_songs = [
['World in My Eyes', 4.86],
['Sweetest Perfection', 4.43],
['Personal Jesus', 4.56],
['Halo', 4.90],
['Waiting for the Night', 6.07],
['Enjoy the Silence', 4.20],
['Policy of Truth', 4.76],
['Blue Dress', 4.29],
['Clean', 5.83]
]
li = []
special_list = []
qty = int(input('Сколько песен выбрать? '))
print()
count = 1
ok = True
while ok:
for _ in range(qty):
if ok:
song = input('Введите название ' + str(count) + ' песни: ')
for elem in violator_songs:
li.extend(elem)
if song not in li:
print('Ошибка. Такой песни в плейлисте нет!')
ok = False
break
else:
special_list.append(song)
count += 1
summ = 0
for i_time in violator_songs:
if i_time[0] in special_list:
summ += i_time[1]
if ok:
print('\nОбщее время звучания песен:', float(round(summ, 2)))
break