Create an algorithm and its corresponding code implementation in Python that counts the number of words in a string.
This is a sentence
def word_count(string):
 words = string.split()
 return len(words)

print(word_count("This is a sentence"))