from time import sleep def countdown_gen(n, consumer): consumer.send(None) while n > 0: consumer.send(n) n -= 1 consumer.send(None) def countdown_con(): while True: n = yield if n: print(f'Countdown {n}') sleep(1) else: print('Countdown Over!') def main(): countdown_gen(5, countdown_con()) if __name__ == '__main__': main()