define a function,character, with parameter values and word that takes in a dictionary of letter values and a string. Based on the values in the dictionary, return the "score" that corresponds with the word parameter. NOTE: Assume all words and letter values will be lowercase.
examples:
values = {'a': 5, 'b': 5, 'c': 5, 'd': 5, 'e': 5, 'f': 5, 'g': 5, 'h': 5, 'i': 5, 'j': 5, 'k': 5, 'l': 5, 'm': 5, 'n': 5, 'o': 5}
character(value,"ade") will return 15
def character(values, word):
score = 0
for c in list(word):
score = score + values[c]
return score
# tests
values = {'a': 5, 'b': 5, 'c': 5, 'd': 5, 'e': 5, 'f': 5, 'g': 5, 'h': 5, 'i': 5, 'j': 5, 'k': 5, 'l': 5, 'm': 5, 'n': 5, 'o': 5}
print(character(values, 'ade'))
OUTPUT:
15
The above code in python has a function character(values, word) which has two parameters values which is a dictionary, and word which is a string. The function returns the score of the word according to value stored in dictionary for particular character.
Get Answers For Free
Most questions answered within 1 hours.