Objective
Create a Python program with your first generator function, which uses yield instead of return.
Instructions
- Define
def countdown(n), which, whilenis greater than 0, yields (yield) the value ofnand reduces it by 1. - Read an integer
n(at least 1). - Show on one line the values produced by the generator, separated by spaces (
print(*countdown(n))) and, on the next line,Liftoff!.
5
5 4 3 2 1
Liftoff!
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise