A Simple Generator
Completed
Write a generator countdown(n) that yields n, n-1, …, 1. Print its values on one line.
Input
One integer.
Output
One line.
Example
Input
5
Output
5 4 3 2 1
Editor
Python
Hints
yield produces a value and pauses the function until the next value is requested.
Solution explanation
Generators produce values lazily, one at a time, without building a list.
Show solution
def countdown(n):
while n > 0:
yield n
n -= 1
print(*countdown(int(input())))