Words Score

Sort by

recency

|

162 Discussions

|

  • + 0 comments
    i, words = input(), input()
    
    def score_words(words):
        vowels=["a","e","i","o","u","y"]
        words = words.split()
        score = 0
        for word in words:
            vowelcount = 0
            for char in word:
                if char in vowels:
                    vowelcount +=1
            if vowelcount % 2 == 0:
                score += 2
            else:
                score += 1 
        print(score)
    
    score_words(words)
    
  • + 0 comments

    Just the ++score has to be converted into score += 1. Rest of the code stays as it is.

    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

    With the use of regex and list comprehension -->

    text = sys.stdin.read().splitlines()[1].split(' ')
    vowels = 'aeiouy'
    score = 0
    
    for word in text:
        if len(re.findall(rf"[{vowels}]", word, flags=re.I))%2 == 0:
            score += 2
            continue
        score +=1
    
    print(score)
    
    • + 0 comments

      Regular resolution of this problem -->

      import sys, re
      
      def score_words(low_words):
          low_words = low_words.splitlines()[1].split(' ')
          vowels = 'aeiuoy'
          score = 0
      
          for word in low_words:
              vowel_count = 0
      
              for letter in word:
                  if letter in vowels:
                      vowel_count += 1
      
              if vowel_count % 2 == 0:
                  score += 2
              else:
                  score += 1
      
          return score
      
      print(score_words(sys.stdin.read()))
      
  • + 1 comment

    As we all know that vowels are a,e,i,o,u and why it has metioned y in the above one.

    • + 0 comments

      "y" is a vowel or a consonant depends on its position and the sound it represents in the word. This versatility makes "y" quite special in the English alphabet!

      So in this case it could be either, but as it was mentioned as being counted as a vowel, we should take it as a vowel

  • + 0 comments
    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))