0% found this document useful (0 votes)
9 views4 pages

Ap CSP Create Task Submit

Uploaded by

aryashpanta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Ap CSP Create Task Submit

Uploaded by

aryashpanta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

# Program code for filtering movies by genre

# Acknowledgments:

# The program structure and initial implementation were inspired by a coding example from an online
tutorial made by Roco Pietrofesa.

# Specifically, the structure and logic for filtering movies based on genres were adapted from the
tutorial.

def filter_movies_by_genre(genre_list, movies_data):

"""

Filters movies based on provided genres.

Parameters:

genre_list (list): List of genres to filter movies.

movies_data (dict): Dictionary containing movie data with associated genres.

Returns:

list: List of filtered movies.

"""

filtered_movies = []

for movie, genres in movies_data.items():

if all(genre.lower() in genres for genre in genre_list):

filtered_movies.append((movie, genres))

return filtered_movies

def main():

"""

Main function to run the program.

"""
# Movie data with associated genres, including happy, sad, angry, etc.

movies_data = {

"Inception": ["mind-bending", "thrilling", "suspenseful", "violent", "thoughtful", "sci-fi"],

"The Shawshank Redemption": ["inspiring", "dramatic", "hopeful", "thoughtful", "drama"],

"The Matrix": ["action-packed", "sci-fi", "dystopian", "violent"],

"Forrest Gump": ["heartwarming", "feel-good", "inspirational", "happy"],

"The Dark Knight": ["intense", "dark", "suspenseful", "action-packed"],

"Pulp Fiction": ["edgy", "quirky", "non-linear","Violent"],

"Interstellar": ["epic", "thought-provoking", "emotional", “sci-fi”],

"The Godfather": ["classic", "intense", "gripping", “drama”],

"Eternal Sunshine of the Spotless Mind": ["surreal", "romantic", "thoughtful", "drama"],

"Fight Club": ["gritty", "mind-bending", "dark", "violent"],

"The Pursuit of Happyness": ["inspiring", "drama", "sad",],

"12 Angry Men": ["intense", "angry", "drama"],

"Inside Out": ["emotional", "animated", "happy"],

"Schindler's List": ["dramatic","emotional", "sad", "drama",],

"Grave of the Fireflies": ["emotional", "animated", "sad"],

"La La Land": ["romantic", "happy", "uplifting"],

"Toy Story": ["animated", "family", “heartwarming”,],

"The Lion King": ["animated", "family",],

"Finding Nemo": ["animated", "family", "heartwarming"],

"The Avengers": ["action-packed", "superhero", "entertaining"],

"Heat": ["action-packed", "dramatic", "violent"],

"The Notebook": ["romantic", "drama", "heartfelt"],

"Titanic": ["romantic", "drama",],

}
previous_movies = []

while True:

# Prompt the user to select genres

print("\nAvailable genres:")

for genre in sorted(set(sum(movies_data.values(), []))):

print("-", genre.capitalize())

user_input = input("\nEnter the genre of movie you want to watch today from the list above, you
can choose multiple to narrow down an option further, separate by comma and no spaces (or type
'exit' to quit): ").strip().lower()

if user_input == 'exit':

break

genre_list = user_input.split(',')

filtered_movies = filter_movies_by_genre(genre_list, movies_data)

previous_movies.extend(filtered_movies)

# Output the list of filtered movies

if filtered_movies:

print("\nThe movies that match the given genre(s) are:")

for movie, genres in filtered_movies:

print(f"{movie} - Genres: {', '.join(genres)}")

more_movies = input("\nWould you like to see more movies? (yes/no): ").strip().lower()

if more_movies != 'yes':
break

else:

print("\nNo movies match the given genre(s).")

# Output previous movies

print("\nPrevious movies in order:")

for movie, genres in previous_movies:

print(f"{movie} - Genres: {', '.join(genres)}")

# Call the main function to run the program

if __name__ == "__main__":

main()

You might also like