8000 Merge pull request #9 from tecladocode/milestone_project_remove_hof · coding794/complete-python-course@9fef426 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9fef426

Browse files
authored
Merge pull request tecladocode#9 from tecladocode/milestone_project_remove_hof
Update milestone project app so that it doesn't use Higher-Order Func…
2 parents 446e06a + df2911a commit 9fef426

File tree

2 files changed

+69
-27
lines changed

2 files changed

+69
-27
lines changed
Lines changed: 30 additions & 27 deletions
< 8000 /tr>
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,55 @@
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: "
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():
22-
name = input("Enter the movie name: ")
6+
title = input("Enter the movie title: ")
237
director = input("Enter the movie director: ")
248
year = input("Enter the movie release year: ")
259

2610
movies.append({
27-
'name': name,
11+
'title': title,
2812
'director': director,
2913
'year': year
3014
})
3115

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):
39-
print(f"Name: {movie['name']}")
22+
def print_movie(movie):
23+
print(f"Title: {movie['title']}")
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_title = input("Enter movie title 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["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)
5053

5154

5255
menu()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Incomplete app!
2+
3+
MENU_PROMPT = "\nEnter 'a' to add a movie, 'l' to see your movies, 'f' to find a movie by title, or 'q' to quit: "
4+
movies = []
5+
6+
7+
# You may want to create a function for this code
8+
title = input("Enter the movie title: ")
9+
director = input("Enter the movie director: ")
10+
year = input("Enter the movie release year: ")
11+
12+
movies.append({
13+
'title': title,
14+
'director': director,
15+
'year': year
16+
})
17+
18+
19+
# Create other functions for:
20+
# - listing movies
21+
# - finding movies
22+
23+
24+
# And another function here for the user menu
25+
selection = input(MENU_PROMPT)
26+
while selection != 'q':
27+
if selection == "a":
28+
pass
29+
elif selection == "l":
30+
pass
31+
elif selection == "f":
32+
pass
33+
else:
34+
print('Unknown command. Please try again.')
35+
36+
selection = input(MENU_PROMPT)
37+
38+
39+
# Remember to run the user menu function at the end!

0 commit comments

Comments
 (0)
0