From 3023eb1179b3bdd0544cbfff45785b20a1284bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E7=BA=A2=E8=BE=89?= <2509165036@student.example.com> Date: Mon, 6 Jul 2026 14:15:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3 | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 3 diff --git a/3 b/3 new file mode 100644 index 0000000..970326a --- /dev/null +++ b/3 @@ -0,0 +1,35 @@ +# ① 找出评分最高和最低的电影,打印电影名 + 评分。 +# ② 统计各类型的电影数量,用字典格式输出。 +# ③ 统计各导演的电影数量,用字典格式输出。 +# ④ 统计 2020 年(含)以后上映的电影数量。 +import json +with open('movie.json', 'r', encoding='utf-8') as f: + data=json.load(f) + # print(data) + +sort_movie=sorted(data,key=lambda x:x["rating"]) +min=sort_movie[0] +max=sort_movie[-1] +print("评分最低的电影",min["title"],min["rating"]) +print("评分最高的电影",max["title"],max["rating"]) +genre_shu={} +for g in data: + ge=g["genre"] + if ge in genre_shu: + genre_shu[ge]+=1 + else: + genre_shu[ge]=1 +print("各类型的电影数量",genre_shu) +director_shu={} +for d in data: + di=d["director"] + if di in director_shu: + director_shu[di]+=1 + else: + director_shu[di]=1 +print("各导演的电影数量",director_shu) +a=0 +for y in data: + if int(y["year"]) >= 2020: + a+=1 +print("2020 年(含)以后上映的电影数量",a)