0
0
FastAPIframework~10 mins

Why databases persist data in FastAPI - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the FastAPI class.

FastAPI
from fastapi import [1]
app = FastAPI()
Drag options to blanks, or click blank then click option'
ADepends
BFastAPI
CResponse
DRequest
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Request or Response instead of FastAPI.
2fill in blank
medium

Complete the code to define a GET route that returns a welcome message.

FastAPI
@app.[1]("/")
async def root():
    return {"message": "Welcome!"}
Drag options to blanks, or click blank then click option'
Aget
Bpost
Cput
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using post or put instead of get for a simple retrieval.
3fill in blank
hard

Fix the error in the code to connect to a SQLite database using SQLAlchemy.

FastAPI
from sqlalchemy import create_engine
engine = create_engine("sqlite:///[1]")
Drag options to blanks, or click blank then click option'
Adatabase.db
Bdb.sqlite3
C:memory:
Dmemory
Attempts:
3 left
💡 Hint
Common Mistakes
Using :memory: creates a temporary in-memory database, not persistent.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that stores word lengths for words longer than 3 characters.

FastAPI
{word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B==
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality or less than instead of greater than for filtering.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that stores uppercase keys and values for items with positive values.

FastAPI
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using k.lower() or wrong comparison operators.