Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
isalpha() solution in Clear category for Three Words by ithink2020
def checkio(words: str) -> bool:
words_list = words.split()
words_in_a_row = 0
for word in words_list:
if word.isalpha():
# Word is all alpha. Add 1 to words_in_a_row
words_in_a_row += 1
if words_in_a_row == 3:
# At least 3 words in succession, return True
return True
else:
# Reset words_in_a_row to 0
words_in_a_row = 0
# Return False if at end of string without words_in_a_row getting to 3.
return False
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
print('Example:')
print(checkio("Hello World hello"))
assert checkio("Hello World hello") == True, "Hello"
assert checkio("He is 123 man") == False, "123 man"
assert checkio("1 2 3 4") == False, "Digits"
assert checkio("bla bla bla bla") == True, "Bla Bla"
assert checkio("Hi") == False, "Hi"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
Feb. 18, 2021