Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions sentiment.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#pip install TextBlob

#import TextBlob
from textblob import TextBlob

text = "Python is a very good language to learn"

obj = TextBlob(text)
from textblob import TextBlob

#returns the sentiment of text
#by returning a value between -1.0 and 1.0
sentiment = obj.sentiment.polarity
def calculate_sentiment(text):
blob = TextBlob(text)
sentiment = blob.sentiment.polarity
return sentiment

print(sentiment)
if __name__ == "__main__":
text = input("Enter the text: ")
try:
sentiment = calculate_sentiment(text)
print(f"Sentiment: {sentiment:.2f}")
except Exception as e:
print(f"Error: {e}")