Question: I had a two part problem. the first part is answered. I need help with the second part not the first part. Please read part


I had a two part problem. 

the first part is answered. 

I need help with the second part not the first part.

Please read part one if needed to assist in part 2.

 

***PART 1***

The problem requires using the function computeScrabbleScore developed in an earlier problem set. Copy the code for the function to the cell below.

 

def computeScrabbleScore(word):
   letter_values = {'a': 1, 'b': 3, 'c': 3, 'd': 2, 'e': 1, 'f':4, 'g'
: 2, 'h':4, 'i':1,'j':8, 'k':5,
'l':1, 'm':3, 'n':1, 'o':1, 'p':3, 'q':10, 'r':1,
's':1, 't':1, 'u':1,'v':8, 'w':4,
                    'x':8, 'y':4, 'z':10}
   sum = 0
   for ch in word.lower():
       sum = sum + letter_values[ch]
   return sum

def wordScore(word_list):
   scrabbleScoreDict = {}
   for word in word_list:
       scrabbleScoreDict[word] = computeScrabbleScore(word)
   return scrabbleScoreDict

def bestWord(word_dict):
   maxWord = max(word_dict, key=word_dict.get)
   return (maxWord, word_dict[maxWord])

# do not change the code below
letter_values = {'a': 1, 'b': 3, 'c': 3, 'd': 2, 'e': 1, 'f':4, 'g': 2, 'h':4, 'i':1,'j':8, 'k':5,
                'l':1, 'm':3, 'n':1, 'o':1, 'p':3, 'q':10, 'r':1, 's':1, 't':1, 'u':1,'v':8, 'w':4,
                'x':8, 'y':4, 'z':10}
word_list = ['Half','a','league','half','a','league','Half','a','league','onward',
        'All','in','the','valley','of','Death','Rode','the','six','hundred',
        'Forward','the','Light','Brigade','Charge','for','the','guns','he','said',
        'Into','the','valley','of','Death','Rode','the','six','hundred']
wordDict = wordScore(word_list)
print(wordDict)
best_word = bestWord(wordDict)
print("The word with the highest score is",best_word[0],"with a score of",best_word[1])

 

Write code that repeatedly prompts the user for a word until the sentinel "None" or "none" is entered. In the loop, call computeScrabbleScore with the word entered then add the word and its value as a key-value pair into the dictionary scrabbleWords. Print scrabbleWords.

def computeScrabbleScore(word):
  letter_values = {'a': 1, 'b': 3, 'c': 3, 'd': 2, 'e': 1, 'f':4, 'g'
: 2, 'h':4, 'i':1,'j':8, 'k':5,
'l':1, 'm':3, 'n':1, 'o':1, 'p':3, 'q':10, 'r':1,
's':1, 't':1, 'u':1,'v':8, 'w':4,
                   'x':8, 'y':4, 'z':10}
  sum = 0
  for ch in word.lower():
      sum = sum + letter_values[ch]
  return sum

def wordScore(word_list):
  scrabbleScoreDict = {}
  for word in word_list:
      scrabbleScoreDict[word] = computeScrabbleScore(word)
  return scrabbleScoreDict

def bestWord(word_dict):
  maxWord = max(word_dict, key=word_dict.get)
  return (maxWord, word_dict[maxWord])
letter_values = {'a': 1, 'b': 3, 'c': 3, 'd': 2, 'e': 1, 'f':4, 'g': 2, 'h':4, 'i':1,'j':8, 'k':5,
               'l':1, 'm':3, 'n':1, 'o':1, 'p':3, 'q':10, 'r':1, 's':1, 't':1, 'u':1,'v':8, 'w':4,
               'x':8, 'y':4, 'z':10}
word_list = ['Half','a','league','half','a','league','Half','a','league','onward',
       'All','in','the','valley','of','Death','Rode','the','six','hundred',
       'Forward','the','Light','Brigade','Charge','for','the','guns','he','said',
       'Into','the','valley','of','Death','Rode','the','six','hundred']
wordDict = wordScore(word_list)
print(wordDict)
best_word = bestWord(wordDict)
print("The word with the highest score is",best_word[0],"with a score of",best_word[1])

 

def computeScrabbleScore(word):
   letter_values = {'a': 1, 'b': 3, 'c': 3, 'd': 2, 'e': 1, 'f': 4, 'g': 2, 'h': 4, 'i': 1, 'j': 8, 'k': 5,
                    'l': 1, 'm': 3, 'n': 1, 'o': 1, 'p': 3, 'q': 10, 'r': 1, 's': 1, 't': 1, 'u': 1, 'v': 8, 'w': 4,
                    'x': 8, 'y': 4, 'z': 10}
   score = 0
   for ch in word.lower():
       score += letter_values.get(ch, 0)
   return score
scrabbleWords = {}
while True:
   word = input("Enter a word (enter 'None' to stop): ")
   if word.lower() == "none":
       break
   score = computeScrabbleScore(word)
   scrabbleWords[word] = score
print(scrabbleWords)

 

***END PART 1***

 

***PART 2***

Alter the above code so that instead of building a dictionary of word-value pairs, you build a list. Each entry of the list is a tuple containing the word and value. Print the list after the loop terminates.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!