Develop a Python program that analyzes the sentiment of a given text input. Sentiment analysis involves determining whether a piece of text expresses positive, negative, or neutral sentiments. The program should utilize the TextBlob library, which provides a simple API for sentiment analysis.
Enter text to analyze sentiment: I love this movie, it's fantastic!
Sentiment: Positive
Polarity: 0.8
Subjectivity: 0.9
Note: Ensure error handling is implemented to handle unexpected inputs or errors during sentiment analysis.
from textblob import TextBlob
def analyze_sentiment(text):
analysis = TextBlob(text)
# Get polarity and subjectivity
polarity = analysis.sentiment.polarity
subjectivity = analysis.sentiment.subjectivity
# Determine sentiment
if polarity > 0:
sentiment = "Positive"
elif polarity < 0:
sentiment = "Negative"
else:
sentiment = "Neutral"
return sentiment, polarity, subjectivity
text = input("Enter text to analyze sentiment: ")
sentiment, polarity, subjectivity = analyze_sentiment(text)
print(f"Sentiment: {sentiment}")
print(f"Polarity: {polarity}")
print(f"Subjectivity: {subjectivity}")
Enter text to analyze sentiment: Happy Sentiment: Positive Polarity: 0.8 Subjectivity: 1.0