From 9596996ac146d516d868d28e1efa90367351edb1 Mon Sep 17 00:00:00 2001 From: calewagner11 <calewagner11@gmail.com> Date: Mon, 20 Feb 2017 16:59:15 -0600 Subject: [PATCH] Created a menu for startup --- sentiment.py | 54 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/sentiment.py b/sentiment.py index fd8f4db..0f71ee2 100644 --- a/sentiment.py +++ b/sentiment.py @@ -5,27 +5,39 @@ import sys def main(): - ans = [] - sentiments = dict() - total = 0 - try: - with open('sentiment.txt', 'r') as f: - lines = f.read().splitlines() # split lines - user_search_value = raw_input('Please enter a word: ') - for line in f.readlines(): - line = line.strip().lower().split() - for words in line: - if words.find(user_search_value): - total += 1 - print(total) - for l in lines: - words = l.split() # split each string in line - ans.append(words) # appending to final ans - print(len(lines)) - var = 'The word ' + str(user_search_value) + ' appears ' + str(total) + ' times with an average sentiment of ' + str(sentiments) - print (var) - except IOError: - print("Error: can\'t find file or read data") + print ('Enter your choice: \n' + '1: Get the score of a word\n' + '2: Get the average score of words in a file (one word per line)\n' + '3: Find the highest/lowest scoring words in a file\n' + '4: Sort words from a file into positive.txt and negative.txt\n' + '5: Exit the program\n') + +choice = raw_input('Enter a number 1-5: ') + +if choice == 5: + print('Goodbye!') + + ans = [] + sentiments = dict() + total = 0 + try: + with open('sentiment.txt', 'r') as f: + lines = f.read().splitlines() # split lines + user_search_value = raw_input('Please enter a word: ') + for line in f.readlines(): + line = line.strip().lower().split() + for words in line: + if words.find(user_search_value): + total += 1 + print(total) + for l in lines: + words = l.split() # split each string in line + ans.append(words) # appending to final ans + print(len(lines)) + var = 'The word ' + str(user_search_value) + ' appears ' + str(total) + ' times with an average sentiment of ' + str(sentiments) + print (var) + except IOError: + print("Error: can\'t find file or read data") pass -- GitLab