Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Striped Words by Krzysztof_Dziedzic
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
DIGITS = "0123456789"
def isVowel(txt):
for x in VOWELS:
if x == txt:
return True
return False
def isConsonant(txt1):
for y in CONSONANTS:
if y == txt1:
return True
return False
def isDigit(txt2):
for z in DIGITS:
if z == txt2:
return True
return False
def checkio(text):
States = []
Counter = 0
Tmp = 0
A = True
text1 = text.upper()
text1 = text1.rstrip(".")
text1 = text1.replace(",", " ")
text1 = text1.replace(".", " ")
text1 = text1 + " ["
print(text1)
print(text1 + "\n")
for x in text1:
#print(x)
if isVowel(x):
States += "V"
elif isConsonant(x):
States += "C"
elif isDigit(x):
States += "Q"
States += "Q"
elif x.isspace() or x == "[":
if x == "[":
break
print(States , ", " , len(States))
for a in range(0,len(States) - 1):
if States[a] != States[a+1]:
if a == len(States) - 2:
Counter = Counter + 1
print("ok")
else:
break
States = []
print(Counter)
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"
Oct. 23, 2016