Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Striped Words by Chramar
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
NUMBERS = "0123456789"
def checkio(text):
cnt=0
text=text.upper()
text=text.replace(",", " ")
text=text.replace(".", " ")
words=text.split()
spr=True
for w in words:
print(w)
spr=True
if len(w)==1:
continue
if w[0] in VOWELS:
for i in range(len(w)):
if i%2==1 and w[i] in VOWELS:
spr=False
break
elif i%2==0 and w[i] in CONSONANTS:
spr=False
break
if spr:
cnt+=1
elif w[0] in CONSONANTS:
for i in range(len(w)):
if i%2==0 and w[i] in VOWELS:
spr=False
break
elif i%2==1 and w[i] in CONSONANTS:
spr=False
break
if spr:
cnt+=1
return cnt
#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"
Nov. 7, 2016