编写一个Python函数，根据给出的文本，计算句子中单词的平均长度并返回结果。


text = "This is a sample sentence. It contains a few words."
```
def avg_word_length(text):
    words = text.split()
    return sum(len(word) for word in words) / len(words)

text = "This is a sample sentence. It contains a few words."
print(avg_word_length(text))
```

Output: `4.285714285714286`