Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Striped Words by pawel1337
VOWELS = "AEIOUYaeiouy"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz"
def checkio(text):
if len(text)==0:
return 0
total = 0
prev = 0
current = True
l = 0
numfound = False
for c in text:
#print(c)
if c in [',', '.', ' ', '?', ';', '-']:
if current == True and prev != 0 and l>1 and numfound == False:
total += 1
current = True
numfound = False
prev = 0
l=0
elif c in VOWELS:
l += 1
if prev == 1:
current = False
prev = 1
elif c in CONSONANTS:
l += 1
if prev == 2:
current = False
prev = 2
else:
numfound = True
l += 1
prev = 3
if current == True and prev != 0 and l>1 and numfound == False:
total += 1
return total
checkio("To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it?")
#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. 4, 2016