generate functionTue, 13 Dec 2022

A string with words and numbers separated by spaces (one space between words and/or numbers). The words consist only of letters. You need to check if there are three words in a row in the original string. For example, the line "start 5 one two three 7 end" has three words in a row. Input: A string with words (str). Output: Answer as a boolean expression (bool), True or False. Examples: checkio("Hello World hello") == True checkio("He is 123 man") == False checkio("1 2 3 4") == False checkio("bla bla bla bla") == True

def checkio(str): cnt = 0 for i in str.split(): cnt = cnt + 1 if i.isalpha() else 0 if cnt >= 3: return True return False

Questions about programming?Chat with your personal AI assistant