Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Striped Words by quis20
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
def check_word(word):
what_next = 0 #0 - no specifed, 1 - vowel, 2 - consonant
for i,ltr in enumerate(word):
if ltr in VOWELS and (what_next == 1 or what_next == 0):
what_next = 2
elif ltr in CONSONANTS and (what_next == 2 or what_next == 0):
what_next = 1
else:
return False
if i == (len(word)-1):
return True
return False
def checkio(text):
text = text.upper()
word = str()
striped_words = 0
for letter in text:
if not (letter in VOWELS) and not (letter in CONSONANTS) and (ord(letter) < 48 or ord(letter) > 57):
if len(word) > 1:
if check_word(word):
striped_words += 1
word = ""
else:
word += letter
if len(word) > 1:
if check_word(word):
striped_words += 1
return striped_words
#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"
Jan. 24, 2016