Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Striped Words by jantechner
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
PUNCTUATION = ".,;? "
def checkio(data):
data = data.upper()
if len(data) == 1:
return 0
if data[1] in PUNCTUATION:
check = False
else:
check = True
counter = 0
for i in range(1, len(data)-1):
if data[i].isdigit():
try:
i = data.index(' ', i)
check = False
except:
return counter
else:
if not data[i] in PUNCTUATION:
if data[i-1] in PUNCTUATION and not data[i+1] in PUNCTUATION:
check = True
elif check == True:
if data[i] in CONSONANTS and data[i-1] in VOWELS:
check = True
elif data[i] in VOWELS and data[i-1] in CONSONANTS:
check = True
elif data[i] in VOWELS and data[i-1] in VOWELS:
check = False
elif data[i] in CONSONANTS and data[i-1] in CONSONANTS:
check = False
else:
if check == True:
counter += 1
check = False
if check == True:
if data[-2] in CONSONANTS and data[-1] in VOWELS:
counter+=1
if data[-2] in VOWELS and data[-1] in CONSONANTS:
counter+=1
if data[-1] in PUNCTUATION:
counter +=1
return counter
#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. 3, 2016