-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLAB3F2.py
More file actions
149 lines (127 loc) · 2.81 KB
/
LAB3F2.py
File metadata and controls
149 lines (127 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
movies = [
{
"name": "Usual Suspects",
"imdb": 7.0,
"category": "Thriller"
},
{
"name": "Hitman",
"imdb": 6.3,
"category": "Action"
},
{
"name": "Dark Knight",
"imdb": 9.0,
"category": "Adventure"
},
{
"name": "The Help",
"imdb": 8.0,
"category": "Drama"
},
{
"name": "The Choice",
"imdb": 6.2,
"category": "Romance"
},
{
"name": "Colonia",
"imdb": 7.4,
"category": "Romance"
},
{
"name": "Love",
"imdb": 6.0,
"category": "Romance"
},
{
"name": "Bride Wars",
"imdb": 5.4,
"category": "Romance"
},
{
"name": "AlphaJet",
"imdb": 3.2,
"category": "War"
},
{
"name": "Ringing Crime",
"imdb": 4.0,
"category": "Crime"
},
{
"name": "Joking muck",
"imdb": 7.2,
"category": "Comedy"
},
{
"name": "What is the name",
"imdb": 9.2,
"category": "Suspense"
},
{
"name": "Detective",
"imdb": 7.0,
"category": "Suspense"
},
{
"name": "Exam",
"imdb": 4.2,
"category": "Thriller"
},
{
"name": "We Two",
"imdb": 7.2,
"category": "Romance"
}
]
# Write a function that takes a single movie and returns True if its IMDB score is above 5.5
def func1(movie):
if (movie["imdb"] > 5.5):
return True
return False
print(func1(movies[7]))
# Write a function that returns a sublist of movies with an IMDB score above 5.5.
def func2(movies):
anslist = []
for i in range(0, len(movies)):
film = movies[i]
if film["imdb"] > 5.5:
anslist.append(film)
return anslist
print(func2(movies))
# Write a function that takes a category name and returns just those movies under that category.
def func3(movies, cat):
answer = []
for i in movies:
zh = i["category"]
if cat == zh:
answer.append(i)
return answer
print(func3(movies, "Action"))
# Write a function that takes a list of movies and computes the average IMDB score.
def avrg(movies):
numofmovies = len(movies)
tot = 0
for i in movies:
tot = tot + i["imdb"]
tot = tot / numofmovies
print(tot)
avrg(movies)
# Write a function that takes a category and computes the average IMDB score.
def func5(movies, cat):
catlist = []
for i in movies:
cot = i["category"]
if cat == cot:
catlist.append(i)
return catlist
def func6(newlist):
numoflist = len(newlist)
av = 0
for i in newlist:
av = av + i["imdb"]
av = av / numoflist
print(av)
func6(func5(movies, "Romance"))
#test