Complete the code to set a rate limit of 100 requests per minute.
rate_limit = [1] # requests per minute
Setting the rate limit to 100 requests per minute helps protect the service from too many requests.
Complete the code to check if the user has exceeded the rate limit.
if requests_made > [1]: return '429 Too Many Requests'
The code checks if the user made more than 100 requests, which is the limit set.
Fix the error in the code to correctly reset the request count after one minute.
if time_since_last_reset > [1]: requests_made = 0
The request count should reset after 60 seconds (1 minute) to enforce the rate limit per minute.
Fill both blanks to create a dictionary that tracks requests per user.
user_requests = [1] # dictionary to store counts user_requests[user_id] = user_requests.get([2], 0) + 1
The dictionary is initialized with {} and the user_id is used as the key to track requests.
Fill all three blanks to implement a simple rate limiter function.
def rate_limiter(user_id): if user_id not in [1]: [1][user_id] = 0 [1][user_id] += 1 if [1][user_id] > [2]: return '[3]' return 'OK'
The function uses the user_requests dictionary to count requests, limits to 100, and returns '429 Too Many Requests' if exceeded.