def count_word_in_string(word, string):count = 0words = string.split()
word = "apple"string = "I have an apple, I have a pen. Apple pen."
print(count_word_in_string(word, string)) # Output: 2
def count_word_in_string(word, string):
for w in words:count = 0
words = string.split()
if w == word:
count += 1
return count
word = "apple"
string = "I have an apple, I have a pen. Apple pen."
print(count_word_in_string(word, string)) # Output: 2