''' DS2000 Spring 2020 Source code from class - building on the user interface example from Tues. This time, we're using lists to compute the senitment analysis or do a straight-up average. February 4, 2020 ''' AUDIENCE = "A" CRITIC = "C" QUIT = "Q" POSITIVE = ["amazing", "perfect", "purrfect", "great", "fantastic", "love", "loved", "likes", "liked", "mind-blowing", "awesome", "worthy", "funny", "beautiful", "best", "magical", "spectacular", "sensational", "fun", "entertaining", "funny", "blast", "incredible"] NEGATIVE = ["bad", "horrible", "waste", "terrible", "boring", "awful", "catastrophe", "cat-astrophe", "disaster", "sickening", "sucks", "blows", "left", "strange", "uncomfortable", "unsettling", "gross", "worst", "atrocious", "horrifying", "horrified", "stupid", "disastrous"] def choose_menu(movie): ''' Function: choose_menu Parameters: none Returns: A letter, a validated choice from the menu ''' print("Welcome to Rotten Huskies for the movie", movie, "\n" "Choose from the following options...\n" "\t", AUDIENCE, "-- Audience rating\n" "\t", CRITIC, "-- Critics consensus\n" "\t", QUIT, "-- Quit") choice = input("Enter your choice now\n") while choice != AUDIENCE and choice != CRITIC and choice != QUIT: choice = input("Invalid, try again\n") return choice def audience_rating(ratings): ''' Function: audience_rating Parameters: nothing (for now) Returns: average audience rating (float 1-5) Does: Computes the average from a list of numerical ratings ''' total = 0 for i in range(len(ratings)): total += ratings[i] avg = total / len(ratings) return avg def critic_rating(review): ''' Function: critic_ratings Parameters: list of strings (each string is a review) Returns: sentiment critics rating (int) Does: Estimates a positive/negative score from a list of narrative critiques from a bunch of critics ''' score = 0 for review in reviews: words = review.split() for word in words: if word in POSITIVE: print("found positive word", word) score += 1 elif word in NEGATIVE: print("found negative word", word) score -= 1 return score