-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovies_list.py
63 lines (42 loc) · 1.49 KB
/
movies_list.py
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
movies = []
def menu():
user_input = input("Enter [a] to add a movie, [l] to see your movies, [f] to find a movie, and [q] to quit.\n-> ")
while user_input != 'q':
if user_input == 'a':
add_movie()
elif user_input == 'l':
show_movies(movies)
elif user_input == 'f':
find_movies()
else:
print("Invalid input!")
user_input = input(
"\nEnter [a] to add a movie, [l] to see your movies, [f] to find a movie, and [q] to quit.\n-> ")
def add_movie():
name = input("Enter the movie name: ")
director = input("Enter the movie directors: ")
year = input("Enter the movie release year: ")
movies.append({
'name': name,
'director': director,
'year': year
})
def show_movies(movies_list):
for movie in movies_list:
show_movies_details(movie)
def show_movies_details(movie):
print(f"Name: {movie['name']}")
print(f"Director: {movie['director']}")
print(f"Release year: {movie['year']}")
def find_movies():
find_by = input("What property of the movie are you looking for? ") # year, name or director
looking_for = input("What are you searching for? ")
found_movies = find_by_attribute(movies, looking_for, lambda x: x[find_by])
show_movies(found_movies)
def find_by_attribute(items, expected, finder):
found = []
for i in items:
if finder(i) == expected:
found.append(i)
return found
menu()