We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Python
  3. Debugging
  4. Words Score
  5. Discussions

Words Score

Problem
Submissions
Leaderboard
Discussions

Sort 112 Discussions, By:

recency

Please Login in order to post a comment

  • frankiepang2010
    3 days ago+ 0 comments

    for python 3, the issue is in the line for (++score). It doesn't add 1.

    It's a operators increment and decrement value of a variable by 1 works for C and Java. But these operators won't work in Python.

    To debug, change it from (++score) => (score += 1)

    0|
    Permalink
  • sanjeevi_krishn
    2 weeks ago+ 0 comments
    def score_words(words):
        a = ['a', 'e', 'i', 'o', 'u','y']
        b = []
        for i in words:
            c = 0
            for j in i:
                if j in a:
                    c += 1
            if c %2 == 0:
                b.append(2)
            else:
                b.append(1)
        return sum(b)
    
    0|
    Permalink
  • dharshan94880_b1
    2 weeks ago+ 0 comments
    def score_words(words: list[str]) -> int:
        """Score words based on how many vowels in a word."""
        score = 0
        for word in words:
            even = True
            for letter in word:
                if letter in {'a', 'e', 'i', 'o', 'u', 'y'}:
                    even = not even
            score += 2 if even else 1
        return score
    
    0|
    Permalink
  • sakshemgotekar2
    2 weeks ago+ 0 comments

    n = int(input()) user_input = input().split()

    def score_words(ui): vowels = ['a','e','i','o','u','y'] count = 0 list1 = [] for i in ui: temp_alpha = list(i) for j in range(len(temp_alpha)): if temp_alpha[j] in vowels: count += 1 if count % 2 ==0: list1.append(2) count = 0 else: list1.append(1) count = 0 return sum(list1) print(score_words(user_input))

    0|
    Permalink
  • enkidupal
    4 weeks ago+ 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    from typing import Sequence
    
    vowels = set('aeiouy')
    
    def is_vowel(c):
        return c in vowels
    
    def score_word(word: str) -> int: 
        return 2 if sum(is_vowel(c) for c in word) % 2 == 0 else 1
        
    def score_words(words: Sequence[str]) -> int:
        return sum(score_word(word) for word in words)
    
    
    n = int(input())
    words = input().split(" ")
    
    
    #print(n)
    #print(word)
    
    print(score_words(words))
    
    0|
    Permalink
Load more conversations

Need Help?


View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy