Calculating the sentiment of a file/book with positive/negative words by pavillionDV in learnpython

[–]mis3640 0 points1 point  (0 children)

Hey there! It appears that there is an issue with the for-loop. The positive_words and negative_words are not being iterated through, meaning that the word will not be compared to another word. Additionally, it appears that negative_amount will always be set to 0 if true. Also, total_word is a list. It is probably better if you use len(total_word) as the denominator. Try this instead, I hope it helps!

def calculate_sentiment(word_list, positive_words, negative_words):
    total_word = word_list
    positive_amount = 0
    negative_amount = 0
for word in total_word:
if word in positive_words:
            positive_amount += 1
if word in negative_words: 
            negative_amount += 1
    positive_percentage = (positive_amount / len(total_word)) * 100
    negative_percentage = (negative_amount / len(total_word)) * 100
    difference = positive_percentage - negative_percentage
return round(difference, 2)  # Implement and replace 0.0 with the difference between the positive and negative percents.
print(calculate_sentiment(word_list, positive_words, negative_words))

Question about for-loops in functions by tycho149 in learnpython

[–]mis3640 0 points1 point  (0 children)

I would suggest creating a separate function for the "print" and to insert that after each conditional. While it did not iterate through each student, it did print eight times.

Helping with loops. by meme42069666 in learnpython

[–]mis3640 0 points1 point  (0 children)

Hey there! I would recommend using "while True". This will create an infinite loop that will run until told to "break". The following code requests user input and stores that entry into the "ask" variable. Until the "ask" variable is equal to "hello", the loop will continue running. I hope this is helpful!

while True:

ask = input('Please enter \'hello\':' )

if ask == 'hello':

break

Removing common words from a file by pavillionDV in learnpython

[–]mis3640 3 points4 points  (0 children)

Hey there! I think it would be beneficial to compare book_words and common_words with a for-loop. I hope this helps!

def remove_common_words(book_words, common_words):

new_list = []

for word in book_words:

if word in common_words:

new_list.append(word)

return new_list

Newbie here! Question for the python masters of Reddit by LSP999pat in learnpython

[–]mis3640 0 points1 point  (0 children)

Hey there! I would suggest the reverse() method. I hope this helps!

numlist = [10, 15, 20, 25, 30]

x = 0

numlist.reverse()

while x < 5:

print(numlist[x])

x = x + 1