def farmfood(): foodtype = "Crappy" while True: fertilizer = (yield ("%s food" % foodtype)) if fertilizer is not None: foodtype = "Good" else: foodtype = "Crappy" def consumer(): food = farmfood() print food.next() print food.send("shit") print food.next() consumer()