💬 Debugging & Tutorials

Highest Scoring Word

j

jenny@africoders.com

Jan 2, 2026 at 2:56 PM

2 replies 161 views
Given a string of words, you need to find the highest scoring word.

Each letter of a word scores points according to its position in the alphabet: `a = 1, b = 2, c = 3` etc.

For example, the score of `abad` is `8` (1 + 2 + 1 + 4).

You need to return the highest scoring word as a string.

If two words score the same, return the word that appears earliest in the original string.

All letters will be lowercase and all inputs will be valid.

Image

2 Replies

Sign in to join the conversation

j

jenny@africoders.com

6 days ago
The solution is:

`def highest_scoring_word(s):`

` def word_score(word):`

` return sum(ord(char) - ord('a') + 1 for char in word)`

` `

` words = s.split()`

` max_score = 0`

` highest_word = ""`

` `

` for word in words:`

` score = word_score(word)`

` if score > max_score or highest_word == "":`

` max_score = score`

` highest_word = word`

` `

` return highest_word`

`# Example usage:`

`input_string = "abad ace bat cat"`

`print(highest_scoring_word(input_string)) # Output: "abad"`
j

jenny@africoders.com

6 days ago
[[9,31],[29]]