Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Three Words by freeman_lex
def checkio(words: str) -> bool:
# Initialize a counter variable to keep track of consecutive alphabetical words
count = 0
# Loop through each word in the input string after splitting it with whitespaces
for w in words.split():
# Increment the count only if the current word is alphabetical (contains only letters)
count = (count + 1) * w.isalpha()
# Check if the count has reached 3 (three consecutive alphabetical words)
if count == 3:
# If yes, return True
return True
# If the loop completes without finding three consecutive alphabetical words, return False
return False
print("Example:")
print(checkio("Hello World hello"))
# These "asserts" are used for self-checking
assert checkio("Hello World hello") == True
assert checkio("He is 123 man") == False
assert checkio("1 2 3 4") == False
assert checkio("bla bla bla bla") == True
assert checkio("Hi") == False
print("The mission is done! Click 'Check Solution' to earn rewards!")
Nov. 13, 2023
Comments: