<s>Human: 写一个 Python 函数，接受一个字符串和一个整数作为参数，并返回该字符串的每个单词的前n个字符，n为整数参数的值。
字符串："Hello world, this is a test."整数参数：5
</s><s>Assistant: def shorten_words(string, n):
    """
    接受一个字符串和一个整数作为参数，并返回该字符串的每个单词的前n个字符。
    """
    words = string.split()
    shortened_words = []
    for word in words:
        shortened_words.append(word[:n])
    return " ".join(shortened_words)

string = "Hello world, this is a test."
n = 5
shortened_string = shorten_words(string, n)
print(shortened_string)  # "Hello world, this is a"
</s>