Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi if anyone could help me that would be great. I\'ve been trying different thin

ID: 3681675 • Letter: H

Question

Hi if anyone could help me that would be great. I've been trying different thing and they always end up not working or print each abbreviation separately. This is what I have but I have a feeling I have to start from scratch. Also this is all related to using Python.

http://pastebin.com/BRTTiuCD
Everything from tweet_str = raw_input('Enter the sentence with abbreviation in it : ').lower() and above is what the teacher gave us to work with.

This homework assignment asks you to practice

using dictionary objects

manipulating sting objects

building your own algorithm using loops

This homework is based on ZyBook Section 4.8 Tweet Decoder and goes beyond the programming practice to challenge your knowledge on dictionary objects, string objects/methods, and loops. To receive a full credit, complete the following requirements.

1. Allow the user to enter a complete tweet (160 characters or less) as a single line of text. Search the resulting string for abbreviations from the dict obejct and print a list of each abbreviation along with its decoded meaning.

2. Convert the user's tweet to a decoded tweet, replacing the abbreviations directly within the tweet and print the decoded tweet.

3. Loop back to get another complete tweet (160 characters or less) from the user.

4. The user types ‘q’ or ‘Q’ (without quotes) instead of a complete tweet for #3 above to end the program.

Explanation / Answer

# Dictionary object containing abbreviation and meaning pairs
# Note that keys and values are all lower case.
abb_dict = {
'lol': 'laughing out loud',
'bfn': 'bye for now',
'cuz': 'because',
'afk': 'away from keyboard',
'nvm': 'never mind',
'iirc': 'if i recall correctly',
'ttyl': 'talk to you later',
'imho': 'in my honest opinion',
'brb': 'be right back'
}

for k, v in abb_dict.items():
print k, v

while True:
# Get a twitter string from a user input
# use lower() to deal with only lower case letters
tweet_str = raw_input('Enter the sentence with abbreviation in it : ').lower()
if tweet_str == "q" or tweet_str =="Q":
break

#Create condition of 160 characters or less
if len(tweet_str) > 160:
print 'Too many characters'
continue

#To seperate every word from user input word by word
wordList = tweet_str.split()
# String to store the new decoded tweet
decoded_tweet = ""
#Assign key and value from dictionary list
#Detect if any keywords from the user input matches any abbreviations
#Decode meaning in list
#For loop to check every key & value on the dictionary list
for i in range(len(wordList)):
if i!=0:
decoded_tweet+=" "
if abb_dict.has_key(wordList[i]):
decoded_tweet+=abb_dict[wordList[i]]
else:
decoded_tweet += wordList[i]

print "decoded tweet: "+decoded_tweet

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote