Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Striped Words by lukasz.bogaczynski
vowels = "AEIOUY"
consonants = "BCDFGHJKLMNPQRSTVWXZ"
punctuations = [',', '.', '!', '?', ";", ':', ' ']
def checkio(text):
prev_was_vowel = text[0] in vowels
prev_was_consonants = text[0] in consonants
num_of_alter = 0
skip_char = False
is_ok = False
for character in text[1:]:
if character in punctuations:
skip_char = False
if is_ok:
is_ok = False
num_of_alter = num_of_alter + 1
prev_was_vowel = False
prev_was_consonants = False
continue
if skip_char:
continue
character = character.upper()
is_vowel = character in vowels
is_consonants = character in consonants
if is_consonants and prev_was_consonants or is_vowel and prev_was_vowel or character.isdigit():
skip_char = True
is_ok = False
continue
is_ok = prev_was_consonants != is_consonants and prev_was_vowel != is_vowel
prev_was_consonants = is_consonants
prev_was_vowel = is_vowel
if is_ok:
num_of_alter = num_of_alter + 1
return num_of_alter
#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"
Oct. 20, 2017