Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Striped words solution in Clear category for Striped Words by kristof.barbaix
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
import string
import re
def checkio(text):
stripedwords=0
str = text.upper()
for x in string.punctuation:
str = str.replace(x," ")
print(str)
#list = str.split()
list = re.split(' |,|; |, |\*|\n',str)
print(list)
for word in list:
striped = 1
if len(word)>1 and word.isalpha():
for x in range(0,len(word)):
#print(word,",",x,",",word[x])
if word[0] in VOWELS:
if x%2 == 0 and word[x] in CONSONANTS:
striped = 0
if x%2 == 1 and word[x] in VOWELS:
striped = 0
if word[0] in CONSONANTS:
if x%2 == 1 and word[x] in CONSONANTS:
striped = 0
if x%2 == 0 and word[x] in VOWELS:
striped = 0
else:
striped = 0
#print(stripedwords,",",striped)
stripedwords = stripedwords + striped
#print(stripedwords)
return stripedwords
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio("My name is ...") == 3, "All words are striped"
assert checkio("Hello world") == 0, "No one"
assert checkio("A quantity of striped words.") == 1, "Only of"
assert checkio("Dog,cat,mouse,bird.Human.") == 3, "Dog, cat and human"
July 30, 2015