Question

Can someone do this first function? Using python and API!

API KEY:  8bb45882c0894d8c1ad25a8dcc157c09

Function name: get_movie_recommendations Parameters: movie_ids (list of ints) Returns: recommended movie titles (list of strings) Description: Write a function that takes in a list of movie IDs. Find the movies corresponding to the IDs. If the popularity of the movie is greater than 20, add the movie title (string) to a list. Return the list of titles. Note: Your function should be able to handle invalid movie ids. Test Cases: >>> test-1 get movie-recommendations ([346364, 17473, 603]) >>print (test_1) [It, The Matrix] >>> test-2 = get movie-recommendations( [672, 314, 12142, 325245, 333333333]) >>print (test_2) [Harry Potter and the Chamber of Secrets

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PYTHON CODE:

# importing the tmdbsimple api
import tmdbsimple as tmdb

# using the provided key
tmdb.API_KEY='8bb45882c0894d8c1ad25a8dcc157c09'

# function begins
def get_movie_recommendations(lst):

    # temporary list to store the movie titles
    r=[]

    # looping through every id in the list
    for i in lst:

        # creating movie object
        movie=tmdb.Movies(i)

        # if the id is valid,
        if movie.id:

            # getting response dictionary from movie object
            response=movie.info()

            # if the popularity is greater than 20, then added to the list
            if response['popularity'] > 20:
                r.append(movie.title)

    # returning the list
    return r
  
      
# testing
if __name__=='__main__':

    print(get_movie_recommendations([346364,17473,603]))
    print(get_movie_recommendations([672,314,12142,325245]))

SCREENSHOT FOR OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Can someone do this first function? Using python and API! API KEY:  8bb45882c0894d8c1ad25a8dcc157c09 Function name: get_movie_recommendations Parameters:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT