Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Python coroutine code

Practice defining coroutine functions, awaiting other coroutines, and running an async entry point.

Intermediate ~8 min read

Challenge 1

Define the function as a coroutine function.

python Your answer
import asyncio



print(asyncio.run(main()))

Press Ctrl⌘Enter to check your answer

Challenge 2

Await the helper coroutine and store its result.

python Your answer
async def get_value():
    return 21

async def main():
    value = 
    return value * 2

import asyncio
print(asyncio.run(main()))

Press Ctrl⌘Enter to check your answer

Challenge 3

Await the greeting coroutine and return its result.

python Your answer
async def greeting():
    return "Hello"

async def main():
    message = 
    return message + ", world!"

import asyncio
print(asyncio.run(main()))

Press Ctrl⌘Enter to check your answer

Challenge 4

Run the coroutine returned by main and print its result.

python Your answer
import asyncio

async def main():
    return 42

print()

Press Ctrl⌘Enter to check your answer