1
+ MENU_PROMPT = "\n Enter 'a' to add a movie, 'l' to see your movies, 'f' to find a movie by name, or 'q' to quit: "
1
2
movies = []
2
3
3
4
4
- def menu ():
5
- user_input = input ("Enter 'a' to add a movie, 'l' to see your movies, 'f' to find a movie, and 'q' to quit: " )
6
- while user_input != 'q' :
7
- if user_input == 'a' :
8
- add_movie ()
9
- elif user_input == 'l' :
10
- show_movies ()
11
- elif user_input == 'f' :
12
- find_by = input ("What property of the movie is that? " )
13
- looking_for = input ("What are you looking for? " )
14
- movie = find_movie (looking_for , lambda x : x [find_by ])
15
- print (movie or 'No movies found.' )
16
- else :
17
- print ('Unknown command-please try again.' )
18
- user_input = input ("\n Enter 'a' to add a movie, 'l' to see your movies, 'f' to find a movie, and 'q' to quit: " )
19
-
20
-
21
5
def add_movie ():
22
6
name = input ("Enter the movie name: " )
23
7
director = input ("Enter the movie director: " )
@@ -32,21 +16,40 @@ def add_movie():
32
16
33
17
def show_movies ():
34
18
for movie in movies :
35
- show_movie_details (movie )
19
+ print_movie (movie )
36
20
37
21
38
- def show_movie_details (movie ):
22
+ def print_movie (movie ):
39
23
print (f"Name: { movie ['name' ]} " )
40
24
print (f"Director: { movie ['director' ]} " )
41
25
print (f"Release year: { movie ['year' ]} " )
42
26
43
27
44
- def find_movie (expected , finder ):
45
- found = []
28
+ def find_movie ():
29
+ search_name = input ("Enter movie name you're looking for: " )
30
+
46
31
for movie in movies :
47
- if finder (movie ) == expected :
48
- found .append (movie )
49
- return found
32
+ if movie ["name" ] == search_name :
33
+ print_movie (movie )
34
+
35
+
36
+ user_options = {
37
+ "a" : add_movie ,
38
+ "l" : show_movies ,
39
+ "f" : find_movie
40
+ }
41
+
42
+
43
+ def menu ():
44
+ selection = input (MENU_PROMPT )
45
+ while selection != 'q' :
46
+ if selection in user_options :
47
+ selected_function = user_options [selection ]
48
+ selected_function ()
49
+ else :
50
+ print ('Unknown command-please try again.' )
51
+
52
+ selection = input (MENU_PROMPT )
50
53
51
54
52
55
menu ()
0 commit comments