|
| 1 | +MENU_PROMPT = "\nEnter 'a' to add a movie, 'l' to see your movies, 'f' to find a movie by title, 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("\nEnter '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 |
| - name = input("Enter the movie name: ") |
| 6 | + title = input("Enter the movie title: ") |
23 | 7 | director = input("Enter the movie director: ")
|
24 | 8 | year = input("Enter the movie release year: ")
|
25 | 9 |
|
26 | 10 | movies.append({
|
27 |
| - 'name': name, |
| 11 | + 'title': title, |
28 | 12 | 'director': director,
|
29 | 13 | 'year': year
|
30 | 14 | })
|
31 | 15 |
|
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): |
39 |
| - print(f"Name: {movie['name']}") |
| 22 | +def print_movie(movie): |
| 23 | + print(f"Title: {movie['title']}") |
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_title = input("Enter movie title you're looking for: ") |
| 30 | + |
46 | 31 | for movie in movies:
|
47 |
| - if finder(movie) == expected: |
48 |
| - found.append(movie) | <
8000
/tr>
49 |
| - return found |
| 32 | + if movie["title"] == search_title: |
| 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