34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
VALUES = {'e': 1, 'a': 1, 'i': 1, 'o': 1, 'n': 1, 'r': 1,
|
|
't': 1, 'l': 1, 's': 1, 'u': 1, 'd': 2, 'g': 2,
|
|
'b': 3, 'c': 3, 'm': 3, 'p': 3, 'f': 4, 'h': 4,
|
|
'v': 4, 'w': 4, 'y': 4, 'k': 5, 'j': 8, 'x': 8,
|
|
'q': 10, 'z': 10}
|
|
|
|
|
|
def worth_of_words(words):
|
|
highest_word = None
|
|
highest_score = 0
|
|
for word in words:
|
|
score = word_score(word)
|
|
if score > highest_score:
|
|
highest_score = score
|
|
highest_word = word
|
|
return highest_word
|
|
|
|
|
|
def word_score(word):
|
|
score = 0
|
|
for letter in word:
|
|
score += VALUES[letter]
|
|
return score
|
|
|
|
|
|
if __name__ == '__main__':
|
|
print("Example:")
|
|
print(worth_of_words(['hi', 'quiz', 'bomb', 'president']))
|
|
|
|
# These "asserts" using only for self-checking and not necessary for auto-testing
|
|
assert worth_of_words(['hi', 'quiz', 'bomb', 'president']) == 'quiz'
|
|
assert worth_of_words(['zero', 'one', 'two', 'three', 'four', 'five']) == 'zero'
|
|
print("Coding complete? Click 'Check' to earn cool rewards!")
|