''' 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. January 31, 2020 ''' AUDIENCE = "A" CRITIC = "C" QUIT = "Q" POSITIVE = ["good", "like", "liked", "awesome", "great", "brilliant", "entertaining", "best", "greatest", "pleasant", "thrilling", "funny"] NEGATIVE = ["bad", "hate", "hated", "crude", "boring", "unpleasant", "dull", "formulaic", "cluttered", "tired", "disaster"] 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: one review (a list of strings) Returns: sentiment score of the review (int) Does: Estimates a positive/negative score from a list of narrative critiques from a bunch of critics ''' score = 0 for word in review: if word in POSITIVE: print("found positive word", word) score += 1 elif word in NEGATIVE: print("found negative word", word) score -= 1 return score