Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Should have used recursion solution in Clear category for Striped Words by belerris
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
import re
def check(text):
#set the alternating value to none
val = None
#if the text is one character or less return false
if len(text) <= 1:
return False
#for each character in the word check what it is
#set alternating value accordingly
#if values is same as previous you know its false
for i in text:
if i.upper() in VOWELS:
if val == 1:
return False
else:
val = 1
elif i.upper() in CONSONANTS:
if val == 0:
return False
else:
val = 0
#if it neither consonant or vowel
else:
return False
return True
def checkio(text):
text = re.findall(r"\w+", text)
count = []
for i in text:
count.append(check(i))
print(count)
return sum(count)
#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"
Feb. 14, 2014
Comments: