Generate a program in Python that counts the number of words in a string.
String: "This is a sentence"
def count_words(string):
    words = 0
    for x in string.split():
        words += 1
    return words