Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Striped Words by bartosz_lyzwa
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
def checkio(text):
striped_words_number=0
words=((((text.upper()).replace(',',' ')).replace('.',' ')).replace('?',' ')).split()
for word in words:
if word.isalpha() and len(word)>1:
if word[0] in VOWELS:
first_type=VOWELS
second_type=CONSONANTS
else:
first_type=CONSONANTS
second_type=VOWELS
is_striped=True
for i in range(len(word)):
if i%2==0:
if word[i] not in first_type:
is_striped=False
break
else:
if word[i] not in second_type:
is_striped=False
break
if is_striped:
striped_words_number+=1
return striped_words_number
#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"
Dec. 12, 2017