<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>
<Below this line, add a link to the EXACT exercise that you are stuck at.>
<In what way does your code behave incorrectly? Include ALL error messages.>I am writing a code that reads movie reviews from a separate text file, learns from that, and then the user inputs a review. The code then uses what it learned to rate the users review.The error is “builtins.AttributeError: ‘dict’ object has no attribute ‘has_key’” it’s probably a simple error but I can not figure out how to fix it. The error appears on line 34.
<What do you expect to happen instead?>
```pythonimport re
import string
class Review:
def init(self,keyword,averageScore=0,occurences=0):
self.keyword=keyword
self.averageScore+averageScore
self.occurences=occurences
def getWord(self):
return self.keyword
def getAvergaeScore(self):
return self.averageScore
def getOccurences(self):
return self.occurences
def addNewScore(self, newScore):
oldScoreSum = self.averageScore * self.occurences
self.occurences = self.occurences + 1
self.average = (oldScore + newScore) / (self.occurences)
def printWordStatistic(self):
print (“Words : " , self.keyword)
print (“Occurences : " , self.occurences)
print (“Average Score : " , self.occurences, “\n\n”)
wordDictionary = {}
fileInstance= open(“movieReviews.txt” , “r”)
fileText = fileInstance.read()
reviewSplits = fileText.split(“movieReviews”)
for review in reviewSplits:
lineSplits = review.split(”\n”)
score = str(lineSplits[0].strip())
for i in range(1,len(lineSplits)):
wordSplits = re.split(”\t| “, lineSplits[i])
for word in wordSplits:
#if word = “”
# continue
if wordDictionary.has_key(word):
wordStatsitic = wordDictionary.geet(word)
wordStatsitic = addNewScore(score)
else:
wordStatsitic = WordStatitic(word, score, 1)
wordDictionary = [word]=wordStatistic
def printAllWordStatisitc(wordDictionary):
for wordStatsitic in wordDictionary.values():
wordStatistic.printWordStatsitic()
def calculateAverageOfReview(review):
review.replace(”\t", " “)
review.replace(”\t", " “)
wordSplits = review.split(” “)
averageScore = 0.0
totalCount = 0;
for word in wordSplits:
if wordDictionary.has_key(word):
averageScore+= wordDictionary.get(word).getAverageScore()
totalCount = totalCount + 1
if totalCount != 0 :
returnaverageScore / totalCount
return -1
while (True):
print (”\nEnter a movie review: ")
while True:
line =input()
averageScore=calculateAverageOfReview(inputReview)
if averageScore !=1:
if averageScore >= 2.50:
print(“Postitive review”)
else:
print(“Negative review”)
<do not remove the three backticks above>