I do not have an intention to ask for an answer, but I want to know if my answer is good for a two-week Python beginner?
Question: (Automate the Boring Stuff with Python/ page 102)
Say you have a list value like this:
spam = ['apples', 'bananas', 'tofu', 'cats']
Write a function that takes a list value as an argument and returns a string with all the items separated by a comma and a space, with
andinserted before the last item. For example, passing the previous spam list to the function would return:
apples, bananas, tofu, and cats
But your function should be able to work with any list value passed to it.
spam = ['apples', 'bananas', 'tofu', 'cats'] def sentence(i): for n in range(0, len(spam) - 1): print(spam[n], end=', ') print('and ' + spam[-1]) sentence(spam)