Define a function count_down() that consumes a number a produces a string counting down to 1

Question:

Define a function count_down() that consumes a number a produces a string counting down to 1.

count_down(3) => "3, 2, 1"
count_down(0) => ""  
count_down(1) => "1"
Asked By: Jennifer Xu

||

Answers:

A possible solution could look like

def count_down(n):
    return ', '.join(str(i) for i in range(n, 0, -1))
    # return ', '.join(map(str, range(n, 0, -1)))

>>> count_down(5)
'5, 4, 3, 2, 1'

join, str, range are very fundamental functions/methods you should read up on in the documentation.

Answered By: user2390182
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.