Words Score

Sort by

recency

|

167 Discussions

|

  • + 0 comments

    For Python3 Platform

    The mistake is in line 14 where it is given ++score. Python doesn't have increment/decrement Operators. So the correct answer is score += 1

    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 = 0
            for letter in word:
                if is_vowel(letter):
                    num_vowels += 1
            if num_vowels % 2 == 0:
                score += 2
            else:
                score += 1
        return score
    
    
    n = int(input())
    words = input().split()
    print(score_words(words))
    
  • + 1 comment
    import re,sys
    pat=re.compile(r'[aeiouy]')
    l=sys.stdin.read().splitlines()[1].split()
    total=0
    for word in l:
        total+=1 if len(re.findall(pat,word))&1 else 2
    print(total)
    
  • + 1 comment
    import re
    n = int(input())
    s = input().split()
    ex = r'[aeiouy]'
    score = 0
    for word in s:
        a = len(re.findall(ex,word))
        if a%2==0:
            score +=2
        else:
            score +=1
    				
            
    print(score)    
        
        
        
    
  • + 1 comment

    import re

    def score_words(words): pattern = re.compile(r'[aeiouy]') sum1=0 for i in words.split(): if len(pattern.findall(i))%2==0: sum1 +=2 else: sum1 +=1 return(sum1) if name == "main": n = int(input()) word = input() print(score_words(word))

  • + 0 comments

    Here is HackerRank Words Score in Python solution - https://programmingoneonone.com/hackerrank-words-score-problem-solution-in-python.html