Score a word by letter positions
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.
- Each lowercase letter a-z adds its position (a=1, b=2, ..., z=26).
- Characters that are not lowercase letters are ignored.
- An empty string scores zero.
word_score(word: string) → int
Where you start
def word_score(word: str) -> int:
Worked examples
| Call | Result |
|---|---|
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")