Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesSenior Deep-DivesModule 4 · Memory + profiling · RecapGenerators: yield from + sendpredict96 / 161
+125 XP
Task
📝 **Task:** Predict the exact output. `outer` delegates to `inner` via `yield from`. Driver does `next(g)`, then `g.send("hi")`, then a final `next(g)` wrapped in try/except. Trace which prints fire and in what order. 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if you get stuck.
Predict the output

Read the code carefully

def inner():
    print("inner-start")
    received = yield 1
    print(f"got:{received}")
    yield 2
    print("inner-end")


def outer():
    print("outer-pre")
    yield from inner()
    print("outer-post")


g = outer()
print(next(g))
print(g.send("hi"))
try:
    next(g)
except StopIteration:
    print("stopped")

What will the program print? Write here:

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…