I am using jypyter notebook and my code keeps giving same error for some inputs:
file0 = open("stopwords.txt", "r")
StopWords=list(file0.read().split('\n'))
file = open("positive-words.txt", "r")
positive_words=list(file.read().split('\n'))
file2 = open("negative-words.txt", "r")
negative_words=list(file2.read().split('\n'))
def evaluate(string,Positive_Points=0,Negative_Points=0):
string=list(string.split())
### print(string)
Output=[]
for s in string:
s=s.lower()
if s not in StopWords:
Output.append(s)
### print(Output)
for word in Output:
### print(word)
if word in positive_words:
Postive_Points+=1
elif word in negative_words:
Negative_Points+=1
return Positive_Points,Negative_Points
next cell in jupyter notebook:
import matplotlib.pyplot as plt
result = evaluate("Everything is nice")
lables = ['Positive','Negative']
colors = ['blue','red']
plt.pie(result, labels=lables, colors=colors, startangle=90, autopct='%.1f%%')
plt.show()
This is how the error looks like:
UnboundLocalError Traceback (most recent call last) in
1 import matplotlib.pyplot as plt
2
----> 3 result = evaluate("Everything is nice")
4 lables = ['Positive','Negative']
5 colors = ['blue','red']
in evaluate(string, Positive_Points, Negative_Points)
21 ### print(word)
22 if word in positive_words:
---> 23 Postive_Points+=1
24 elif word in negative_words:
25 Negative_Points+=1
UnboundLocalError: local variable 'Postive_Points' referenced before assignment