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
Sort by
recency
|
164 Discussions
|
Please Login in order to post a 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))
Here is HackerRank Words Score in Python solution - https://programmingoneonone.com/hackerrank-words-score-problem-solution-in-python.html
Just the ++score has to be converted into score += 1. Rest of the code stays as it is.
With the use of regex and list comprehension -->