Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple with re and set solution in Clear category for Striped Words by graffme
import re
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
#rozbij na tablice ze słowami o dużych literach!
#sprawdź czy jest słowem (czy nie ma cyfr i ma więcej niż jedną literę)
#ustaw licznik słów na 0
#przeiteruj słowa???
def isword(string):
if string.isalpha():
return True
else:
return False
def checkio(text):
uppertext = text.upper()
wordList = re.sub("[^\w]", " ", uppertext).split()
countStriped = 0
for word in wordList:
if len(word) > 1:
oddpos = word[::2]
evenpos = word[1::2]
if ((set(evenpos).issubset(set(VOWELS)) and set(oddpos).issubset(set(CONSONANTS)) or set(oddpos).issubset(set(VOWELS)) and set(evenpos).issubset(set(CONSONANTS)))):
#jeśli even to samogłoski a odd to spółgłoski lub na odwrót
countStriped = countStriped + 1
return countStriped
#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"
Jan. 11, 2017