Words Score HackerRank Solution

This Python program is designed to calculate the score of a list of words. The score is determined by the number of vowels in each word. If a word has an even number of vowels, it contributes 2 points to the total score. If a word has an odd number of vowels, it contributes 1 point to the total score.

Secure your next interview 🎯

CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷

Here is the Words Score HackerRank Solution HackerRank solution using CodeRankGPT:

The solution works by iterating over each word in the input list. For each word, it counts the number of vowels using a helper function 'is_vowel'. This function checks if a letter is in the list of vowels ['a', 'e', 'i', 'o', 'u', 'y']. The number of vowels in a word is then used to calculate the score for that word. If the number of vowels is even, 2 points are added to the total score. If the number of vowels is odd, 1 point is added. The total score is then returned.


def is_vowel(letter):
    return letter in ["a", "e", "i", "o", "u", "y"]


def score_words(words):
    score = 0
    for word in words:
        num_vowels = sum(1 for letter in word if is_vowel(letter))
        score += 2 if num_vowels % 2 == 0 else 1
    return score

If you have a HackerRank coding test coming up, you can use CodeRankGPT to your advantage. It will assist you during your interview and help ensure you get the job.

AI is here now, and other candidates might be using it to get ahead and win the job. 🧐

Built on Unicorn Platform