8000 Update milestone project app so that it doesn't use Higher-Order Func… · DORELAS/complete-python-course@0394605 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0394605

Browse files
committed
Update milestone project app so that it doesn't use Higher-Order Function. Intead it now uses a dict-based menu and the search is a movie name-only search.
1 parent 446e06a commit 0394605

File tree

1 file changed

+27
-24
lines changed
  • course_contents/3_first_milestone_project/milestone_1

1 file changed

+27
-24
lines changed
Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
1+
MENU_PROMPT = "\nEnter 'a' to add a movie, 'l' to see your movies, 'f' to find a movie by name, or 'q' to quit: "
12
movies = []
23

34

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-
215
def add_movie():
226
name = input("Enter the movie name: ")
237
director = input("Enter the movie director: ")
@@ -32,21 +16,40 @@ def add_movie():
3216

3317
def show_movies():
3418
for movie in movies:
35-
show_movie_details(movie)
19+
print_movie(movie)
3620

3721

38-
def show_movie_details(movie):
22+
def print_movie(movie):
3923
print(f"Name: {movie['name']}")
4024
print(f"Director: {movie['director']}")
4125
print(f"Release year: {movie['year']}")
4226

4327

44-
def find_movie(expected, finder):
45-
found = []
28+
def find_movie():
29+
search_name = input("Enter movie name you're looking for: ")
30+
4631
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)
5053

5154

5255
menu()

0 commit comments

Comments
 (0)
0