isalpha() vs isdigit(). solution in Clear category for Three Words by tigercat2000
# Split the string into an array using the default settings (any whitespace)
wordarray = words.split()
# Initialize a successive word counter at 0
count = 0
# Iterate over the word array to check for numbers
for word in wordarray:
# Check if the word only contains alphabetical characters.
# It does, great, increment the counter.
count = count + 1
# Because we want to return True if there are ever three successive words, we just check inside the loop.
if(count >= 3):
# It didn't reach three, and we reached something that isn't alphabetical. Reset the counter.
count = 0
# We never reached three or more successive words in the loop, so, it's not a sentence.
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
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"
Nov. 5, 2016