dictionary = {}
while True:
command = input('Введите команду: ')
if command != 'exit' and command != 'list' and command != 'add' and command != 'delete' and command != 'rate' and command != 'find':
print('Error')
continue
if command == 'exit':
break
if command == 'list':
for key in dictionary.keys():
average = 0
if len(dictionary[key]) == 0:
print(f'Фильм {key} не оценивался')
else:
for key1 in dictionary[key].keys():
average += dictionary[key][key1]
print(f'{key} средняя оценка: {average / len(dictionary[key])}')
continue
film = input('Введите название фильма: ')
if command == 'add':
if film in dictionary:
print('Error')
else:
dictionary[film] = {}
elif command == 'delete':
if film in dictionary:
del dictionary[film]
else:
print('Error')
elif command == 'rate':
name = input('Имя пользователя: ')
rate = float(input('Оценка: '))
if 0 < rate
dictionary[film][name] = rate
else:
print('Error')
elif command == 'find':
if len(dictionary[film]) == 0:
print('Фильм не оценивался')
continue
for name, rate in dictionary[film].items():
print(f'{name} поставил оценку: {rate}')
average = 0
for key in dictionary[film].keys():
average += dictionary[film][key]
print(f'Средняя оценка: {average / len(dictionary[film])}')