Editor

Gather Concurrent Results

Advanced · Write the code · from Python Async/Await: Write Non-Blocking Code from Scratch

From the lesson: Python Async/Await: Write Non-Blocking Code from Scratch

Imagine you're a chef in a busy kitchen. You don't stand and watch the oven for 20 minutes while your pasta boils on another burner. Instead, you start the oven, move to the pasta, then check the salad -- all without waiting idle. That's exactly what asynchronous programming does for your code.

Read the lesson

Write an async def function called double that takes x, waits 0.1 seconds with asyncio.sleep, and returns x * 2. Then run double(1), double(2) and double(3) at the same time with asyncio.gather() and print the list of results.

import asyncio
# Write double, then gather three calls and print the results

What Check runs

Your code runs first, then each of these lines. The output must match exactly.

RunsExpected output
import inspect print(inspect.iscoroutinefunction(double))[2, 4, 6] True

More Async and Await exercises

All Python exercises · 50 practice problems · Advanced Python quiz