What to send? (q to quit): birthday card
Thank you for sending me birthday card
What to send? (q to quit): postcard
Thank you for sending me postcard
What to send? (q to quit): q
We appreciate your business
Note: David Beazely is not in favor of having having a single yield both output and take input, as above, regarding such a double-duty yield as too confusing. My code might count as demented in his book.
One of my favorite use of the generator-with-send ability patterns is what I call Tractor in a Farm [nTM].
Farm(ville) is an n x m array of dots or other character, could be numbers, and a Tractor is an iterator following some raster pattern, of row: each column, next row: each column and so on.
When it finishes row 0 it jumps to the start of row 1, so not really a tractor -- more like how people read these left-to-right languages (like you're reading now). If the field were a cylinder, with East and West connecting, the tractor would go in a North to South spiral.
At the bottom right, a Tractor starts over at the top left (so a donut?).
Change in [row][column] (position) is what next() has the tractor do (there's a __next__ method).
But then "fuel level" is dropping with each advance in some models, and without the occasional "send" of more fuel, the tractor will come to a grinding halt in the middle of a field somewhere (demented, but good for learning purposes).
What's useful about this pattern is it's all "ASCII art" or "Unicode art" at first, but yet gives the idea of "pixels" (row, column) and therefore "pixel depth" (the bits needed to define a character), so the transition to a discussion of binary files, say with R, G, B layers, is pretty easy.
The iterator : iterable relationship, between Tractor(s) : Field is pretty intuitive also, owing to the extended metaphor. The tractor is even simpler than the turtle concept deriving from Logo, as the tractor has a fixed and closed path.
Finally, said tractors have a "read" and "write" verbs, or "sense" and "plant", meaning they're able to "write" to whatever cell (patch of Field) they're in (over), replacing the current character with another if need be, according to whatever rule.
In Pythonic Andragogy slides, a TextWriterTractor (subclass of Tractor) starts writing a user-provided phrase at whatever initially passed-in (x,y) position in the field. Example: Just Use It.
A CropCircleTractor (another subclass) reads the Field as complex numbers and plants "@" where z = z * z + current(row, column) doesn't spiral out after n iterations. Result: A Mandelbrot Set.
Pythonic Andragogy slides:
(not saying "not for kids")
An ongoing theme:
Kirby
(see last code cell for mysterious Pi generator discussed here on edu-sig in chapters past)