Complete the code to load the API key from an environment variable.
import os api_key = os.getenv([1])
The environment variable name must be a string, so it needs quotes. "API_KEY" is the correct string key.
Complete the code to check if the API key is missing and raise an error.
if [1] is None: raise ValueError("API key is missing")
Checking if api_key is None is the correct way to detect a missing environment variable.
Fix the error in the code to securely store the API key in a variable.
def store_key(): [1] = os.getenv("API_KEY") return api_key
The variable used inside the function must match the returned variable name. Using 'api_key' is correct.
Fill both blanks to create a function that validates the API key length and raises an error if invalid.
def validate_key(key): if len(key) [1] 32: raise ValueError("Invalid API key length") return True
The API key length should be less than 32 to raise an error if too short.
Fill all three blanks to create a dictionary comprehension that maps API key names to their masked versions if the key length is valid.
masked_keys = [1]: key[:4] + '****' + key[-4:] for [2], key in keys.items() if len(key) [3] 32
The dictionary comprehension syntax requires curly braces and key-value pairs. The length check uses '<=' to allow keys of length 32.