22 lines
709 B
Python
22 lines
709 B
Python
import json
|
|
|
|
# 读取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']}") |