← Back to Recursion
Question 616
Join Words With Commas
Join Words With Commas
Write join_words(words: list[str]) -> str that returns the words joined into one string with a comma and a space between each pair, and nothing after the last word, by recursion and without .join(): a list of exactly one word returns that word; otherwise the result is the first word, then ", ", then the joined rest of the list (the slice words[1:]). Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one line of words separated by spaces, at least one, which the tests read into a list and pass to your function before printing the string it returns.
Expected Output:
red, green, blue= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
RecursionSlicing
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.