Question: I have problem with this code [evaluate trial6.py] analyze_file(['it seem happyt to say', happy she'son!'], ['happy', 'love', 'joy'], ['sad', 'angry'])) Traceback (most recent call last):

I have problem with this code

[evaluate trial6.py] analyze_file(['it seem happyt to say', "happy she'son!'], ['happy', 'love', 'joy'], ['sad', 'angry'])) Traceback (most recent call last): Python Shell, prompt 2, line 1 Syntax Error: EOL while scanning string literal: , line 1, pos 103

from typing import List

def analyze_word(word: str, pos_words: List[str], neg_words: List[str]) -> int: """ Given a word, a list of positive words (all in lowercase), and a list of negative words (all in lowercase), return whether or not the word is positive, negative or neutral.

For a positive word, return 1. For a negative word, return -1. For a neutral word (one that does not appear in either the negative words list nor the positive words list), return 0. >>> ("happy", ['happy', 'love'], ['sad', 'angry']) 1 >>> ("angry", ['happy', 'love', 'joy'], ['sad', 'angry', 'bad']) -1

>>> ("LOVE", ['happy', 'love', 'joy'], ['sad', 'angry', 'bad']) 1

>>> ("sAd", ['happy', 'love', 'joy'], ['sad']) -1 >>> ("okay", ['happy', 'love', 'joy'], ['sad', 'angry']) 0 """

word = word.strip().lower() if word in pos_words: return 1 elif word in neg_words: return -1 else: return 0

def analyze_file(words: List[str], pos_words: List[str], neg_words: List[str]) -> int: """ Given the name of a file, a list of positive words (all in lowercase), and a list of negative words (all in lowercase), return some interesting data about the file in a tuple, with the first item in the tuple being the positivity score of the contents of this file, and the rest of the items being whatever else you end up analyzing. (Helper functions are highly encouraged here.) How to calculate positivity score: For every word that is pos itive in the file (based on the words in the list of positive words) add 1 to the score. For every negative word (based on the list of negative words), subtract 1 from the score. Any neutral words (those that do not appear in either list) do not affect the score in any way. analyze_file("angry sad", ['happy', 'love', 'joy'], ['sad', 'angry', 'bad']) analyze_file("sAd to be ? in such angry", ['happy', 'love', 'joy'], ['sad']) analyze_file(["sAd to be ? in such angry"], ['happy', 'love', 'joy'], ['sad', 'angry']) analyze_file(['it seem happyt to say', "happy she'son!'], ['happy', 'love', 'joy'], ['sad', 'angry'])) """ words = words.split()

for word in words:

this_score = analyze_word(word, pos_words, neg_words)

if this_score > 0: positive += 1

elif this_score < 0: negative += 1

else: neutral += 1

score = positive - negative print (score, positive, negative, neutral)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!