본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 78

반응형

Q>

Hey, are you ready for a Scrabble game party?

(Scrabble 게임 파티 준비 됐니?)
You have a list of words and you have to find only one that is the most valuable among them.

(당신은 단어 목록을 가지고 있으며, 그 중 가장 가치가있는 단어 하나만 찾아야합니다.)
Rules:

(규칙 :)
The worth of each word is equivalent to the sum of letters which it consists of.

(각 단어의 가치는 그것이 구성하는 문자의 합계와 같습니다.)
The values of the letters are as follow:

(글자의 값은 다음과 같습니다. )


e, a, i, o, n, r, t, l, s, u = 1
d, g = 2
b, c, m, p = 3
f, h, v, w, y = 4
k = 5
j, x = 8
q, z = 10


For example, the worth of the word 'dog' is 5, because 'd' = 2, 'o' = 1 and 'g' = 2.

(예를 들어, 'dog'라는 단어의 가치는 'd'= 2, 'o'= 1 및 'g'= 2이기 때문에 5입니다.)

 

Input: A list of words.

         (단어 목록.)

 

Output: The most valuable word.

           (가장 귀중한 단어.)

 

Example:

worth_of_words(['hi', 'quiz', 'bomb', 'president']) == 'quiz'
worth_of_words(['zero', 'one', 'two', 'three', 'four', 'five']) == 'zero'

 

How it is used: For the lexicographic analysis of the texts.

                     (텍스트의 사전 편집 분석에 사용됩니다.)

 

Precondition:
2 <= words <= 10
Real words only

(실제 단어 만)
lowercase letters only

(소문자 만)

 

A>

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):
    #replace this for solution
    return max(words, key=lambda s: sum(VALUES[i] for i in s))

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!")

 

O>

Example:
quiz
Coding complete? Click 'Check' to earn cool rewards!

Process finished with exit code 0

 

S>

https://py.checkio.org

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 80  (0) 2019.06.20
Python Learn the basics Quiz 79  (0) 2019.06.20
Python Learn the basics Quiz 77  (0) 2019.06.20
Python Learn the basics Quiz 76  (0) 2019.06.20
Python Learn the basics Quiz 75  (0) 2019.06.20