Charlotte has a Netflix account with thousands of movies and TV shows. She wants to create a program that can recommend a movie or TV show for her to watch based on her previous viewing history.
To do this, Charlotte has collected a dataset of her previous viewing history in a text file called "viewing_history.txt". Each line of the file contains the title of a movie or TV show she has watched, followed by a comma, and the genre of the movie or TV show.
Charlotte also has a list of favorite genres, which she has stored in a separate text file called "favorite_genres.txt". Each line of the file contains a single genre.
Your task is to write a program that uses this data to recommend a movie or TV show for Charlotte to watch. Your program should satisfy the following requirements:
1. The program should read in the "viewing_history.txt" file and store the data in a list of tuples, where each tuple contains the title of a movie or TV show and its genre.
2. The program should read in the "favorite_genres.txt" file and store the data in a list of strings.
3. The program should define a subroutine that takes the list of tuples and the list of favorite genres as input, and returns a list of movies or TV shows that match one of the favorite genres.
4. The program should use the "random" module to randomly select a movie or TV show from the list returned by the subroutine.
5. The program should print the title of the selected movie or TV show to the console.
This question requires you to create your own text file
Starter code:
import random
def get_viewing_history(filename):
# TODO: Implement this function
pass
def get_favorite_genres(filename):
# TODO: Implement this function
pass
def get_recommendations(viewing_history, favorite_genres):
# TODO: Implement this function
pass
if __name__ == '__main__':
viewing_history = get_viewing_history('viewing_history.txt')
favorite_genres = get_favorite_genres('favorite_genres.txt')
recommendations = get_recommendations(viewing_history, favorite_genres)
if recommendations:
recommendation = random.choice(recommendations)
print(recommendation[0])
else:
print('Sorry, no recommendations available.')