Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Striped Words by wojtek96
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
def try_w(word,a):
if word == '':
return 0
for i in word:
if i.isdigit():
return 0
if a == 0:
if i in VOWELS:
return 0
a = 1
else:
if i in CONSONANTS:
return 0
a = 0
return 1
def checkio(text):
count = 0
text = text.upper() + ' '
list = []
for i in text:
if i == "." or i == "," or i == ' ':
if text[:text.find(i)] != '':
list.append(text[:text.find(i)])
text = text[text.find(i)+1:]
for j in range(len(list)):
n = 1
if list[j][0] in VOWELS:
n = 0
if not (list[j][0].isdigit()):
list[j] = try_w(list[j][1:],n)
else:
list[j] = 0
if n == 1:
n = 0
else:
n = 1
return sum(list)
#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"
Dec. 15, 2016