Complete the code to set a maximum number of API calls per minute.
max_calls_per_minute = [1]The variable max_calls_per_minute should be set to a positive integer to limit API calls.
Complete the code to check if the current usage exceeds the budget.
if current_usage [1] budget_limit: print('Budget exceeded')
We want to detect when usage is greater than the budget limit to trigger an alert.
Fix the error in the code that resets the usage counter after a time window.
if time.time() - last_reset_time [1] reset_interval: usage_count = 0 last_reset_time = time.time()
The usage counter should reset when the elapsed time is greater than or equal to the reset interval.
Fill both blanks to create a dictionary comprehension that tracks usage per user only if usage is below the limit.
usage_per_user = {user: usage[1] for user, usage in user_usage.items() if usage [2] limit}The comprehension adds usage values and filters users with usage less than the limit.
Fill all three blanks to create a rate limiter function that returns True if under limit and updates usage.
def rate_limiter(user): if usage.get(user, 0) [1] limit: usage[user] = usage.get(user, 0) [2] 1 return [3] return False
The function checks if usage is less than limit, increments usage by 1, and returns True to allow the action.
