Drill

ProblemsPython › games

Score a word by letter positions

easygamesPython

A word game scores each letter by its position in the alphabet: a is 1, b is 2, and so on up to z is 26.

word_score(word: string) → int

Solve it in the editor →

Where you start

def word_score(word: str) -> int:
    

Worked examples

CallResult
word_score("abc")6
word_score("hello")52
word_score("")0
word_score("a")1

Hint

Subtract the character code of a from each letter to get its value.

Reference solution in Python
def word_score(word: str) -> int:
    return sum(ord(c) - 96 for c in word if "a" <= c <= "z")

The same problem in another language

More games problems in Python