Files
task-2-3-File-Operations/26331,09test4.py
2026-03-31 11:22:15 +08:00

18 lines
623 B
Python

import json
with open('movies.json', 'r', encoding='utf-8') as f:
movies = json.load(f)
total = sum(float(m['rating']) for m in movies)
average = total / len(movies)
print(f'Top10 电影平均分: {average:.2f}')
highest = max(movies, key=lambda m: float(m['rating']))
print(f'\n评分最高的电影:')
print(f" {highest['rank']}. {highest['title']} ({highest['en_title']})")
print(f" 评分: {highest['rating']}")
with_quote = [m for m in movies if m['quote']]
print(f'\n有经典台词的电影: {len(with_quote)}')
for m in with_quote:
print(f" \"{m['quote']}\" —— {m['title']}")