checkio home MonkeyTyping
checkio home MonkeyTyping
def count_words(text, words): cnt = 0 for w in words: if (w in text.lower()) == True: cnt += 1 else: continue #pass return cnt if __name__ == '__main__': #These "asserts" using only for self-checking and not necessary for auto-testing assert count_words("How aresjfhdskfhskd you?", {"how", "are", "you", "hello"}) == 3, "Example" assert count_words("Bananas, give me bananas!!!", {"banana", "bananas"}) == 2, "BANANAS!" assert count_words("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.", {"sum", "hamlet", "infinity", "anything"}) == 1, "Weird text" print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
・単語が一致した場合にカウントアップ