-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovie_collection_function.py
More file actions
119 lines (81 loc) · 3.73 KB
/
Copy pathmovie_collection_function.py
File metadata and controls
119 lines (81 loc) · 3.73 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#empty list that movies are added to (in lieu of a database)
movies = []
#the menu prompt for users to choose a selection/action
menu = ("\nWould you like to review your movie collection, add a movie, remove a movie, or end the program? "
"Your options are: 'review', 'add', 'find', 'quit': \n")
#information needed to add a movie and how it is stored as a dictionary
def add_movie():
title = input("What is the title of the movie: ")
director = input("What is the director of the movie: ")
release_year = input("What is the release year of the movie: ")
# release_year = int(release_year)
movies.append({
'title': title,
'director': director,
'year': release_year,
})
#the process for reviewing movies
def review_movie():
for movie in movies:
print_movie(movie)
#how movies are printed when review; related to the fucntion immediately above this
def print_movie(movie):
print(f"Title: {movie['title']}")
print(f"Director: {movie['director']}")
print(f"Release Year: {movie['year']}")
#the process for finding movies
def find_movie():
search_movie = (input("Which movie do you want to find in your collection? "))
for movie in movies:
if movie['title'] == search_movie:
print_movie(movie)
#user options dictionary instead of a long list of if-else statements
user_options = {
"add": add_movie,
"review": review_movie,
"find": find_movie,
}
#the main function that is called when the program is activated
def user_menu():
selection = input(menu)
while selection != "quit":
if selection in user_options:
selected_option = user_options[selection]
selected_option()
else:
print("Unknown selection, please try again")
selection = input(menu)
user_menu()
# #the five minute version of the more complete fucntion above
# movies = []
# user_options = input("Would you like to review your movie collection, add a movie, remove a movie, or end the program? "
# "Your options are: 'review', 'add', 'quit': ")
# #what data for each movie to store: title, director, release year
# #movie storage: add movies to a list with append
# while user_options != "quit":
# if user_options == "review":
# print(movies)
# user_options = input("Would you like to review your movie collection, add a movie, remove a movie, or end the program? "
# "Your options are: review, add, remove, quit: ")
# elif user_options == "add":
# title = input("What is the title of the movie: ")
# director = input("What is the director of the movie: ")
# release_year = input("What is the release year of the movie: ")
# release_year = int(release_year)
# movies.append({
# 'title': title,
# 'director': director,
# 'year': release_year,
# })
# user_options = input("Would you like to review your movie collection, add a movie, remove a movie, or end the program? "
# "Your options are: review, add, remove, quit: ")
# elif user_options == "review":
# print(movies)
# user_options = input("Would you like to review your movie collection, add a movie, remove a movie, or end the program? "
# "Your options are: review, add, remove, quit: ")
# else:
# print("Program terminated successfully")
# user_options = input("Would you like to review your movie collection, add a movie, remove a movie, or end the program? "
# "Your options are: review, add, remove, quit: ")
# # print(movies) #testing user inputs being properly recorded
# print(user_options)