Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Striped Words by voxes96
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
def checkio(text):
text = text.replace(",", " ")
text = text.replace(".", " ")
text = text.replace("?", " ")
text = text.replace("!", " ")
text = text.strip(" ")
text = text.upper()
arr = text.split()
res = 0
for i in range(len(arr)):
word = arr[i]
t = True
if(len(word) < 2):
t = False
continue
elif(word[0] in VOWELS):
for j in range(len(word)):
if(j%2==0 and word[j] in VOWELS):
continue
elif(j%2==1 and word[j] in CONSONANTS):
continue
else:
t = False
else:
for j in range(len(word)):
if(j%2==0 and word[j] in CONSONANTS):
continue
elif(j%2==1 and word[j] in VOWELS):
continue
else:
t = False
if(t == True):
res = res + 1
return res
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
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"
Oct. 30, 2016