Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

contains_word() 2 Input Parameters: a word (string) and a message (string) Retur

ID: 3829885 • Letter: C

Question

contains_word() 2 Input Parameters: a word (string) and a message (string) Return: True or False depending on if the word is in the message Checks to see if one string (called word) is inside another (called msg). Although you could loop through the characters of the 2 strings, it would be complex and inefficient. The best approach is to use the 'in' operator directly. Look at the examples below: "bob" in "lisallybobtom" True "bob" in "lisallyjohntom" False Below are some example function calls and return values. You should test them by having your program call the function and print out the return value. (You can erase your test code later.) contains_word("pizza", "my pizza is tasty") True contains_word("dog", "my pizza is tasty") False

Explanation / Answer

def contain_words(word, msg):
return word in msg

print(contain_words("dog", "my pizza is tasty"))
print(contain_words("pizza", "my pizza is tasty"))

# code link: https://paste.ee/p/Uy1qM