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.
- Prepare
- Python
- Debugging
- Words Score
- Discussions
Words Score
Words Score
+ 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 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 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 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 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))
Load more conversations
Sort 112 Discussions, By:
Please Login in order to post a comment