Challenge - 5 Problems
API Analytics Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
API Request Count Calculation
Given the following API usage log data, what is the total number of requests made to the API?
Rest API
api_logs = [
{"endpoint": "/users", "method": "GET"},
{"endpoint": "/users", "method": "POST"},
{"endpoint": "/orders", "method": "GET"},
{"endpoint": "/users", "method": "GET"},
{"endpoint": "/orders", "method": "POST"}
]
total_requests = len(api_logs)
print(total_requests)Attempts:
2 left
💡 Hint
Count each dictionary entry as one request.
✗ Incorrect
The list contains 5 dictionaries, each representing one API request, so the total is 5.
🧠 Conceptual
intermediate1:30remaining
Understanding API Rate Limiting
Which of the following best describes the purpose of API rate limiting?
Attempts:
2 left
💡 Hint
Think about controlling traffic to the API.
✗ Incorrect
Rate limiting controls how many requests a client can make to protect the API from being overwhelmed.
❓ Predict Output
advanced2:00remaining
Calculating Average Response Time
What is the output of the following code that calculates the average response time from API metrics?
Rest API
response_times = [120, 150, 100, 130, 110] avg_response_time = sum(response_times) / len(response_times) print(round(avg_response_time))
Attempts:
2 left
💡 Hint
Sum all times and divide by count, then round to nearest integer.
✗ Incorrect
Sum is 610, divided by 5 is 122.0, rounded is 122.
🔧 Debug
advanced2:30remaining
Identify the Error in API Usage Data Aggregation
What error will the following code raise when trying to aggregate API calls by endpoint?
Rest API
api_calls = [
{"endpoint": "/login", "count": 10},
{"endpoint": "/logout", "count": 5},
{"endpoint": "/login", "count": 7}
]
aggregated = {}
for call in api_calls:
aggregated[call["endpoint"]] += call["count"]
print(aggregated)Attempts:
2 left
💡 Hint
Check if dictionary keys exist before adding.
✗ Incorrect
The dictionary 'aggregated' is empty initially, so accessing aggregated[call["endpoint"]] before assignment causes KeyError.
🚀 Application
expert3:00remaining
Determine the Number of Unique API Users
Given the following API usage data, how many unique users accessed the API?
Rest API
api_usage = [
{"user_id": "u1", "endpoint": "/data"},
{"user_id": "u2", "endpoint": "/data"},
{"user_id": "u1", "endpoint": "/status"},
{"user_id": "u3", "endpoint": "/data"},
{"user_id": "u2", "endpoint": "/status"}
]
unique_users = len(set(entry["user_id"] for entry in api_usage))
print(unique_users)Attempts:
2 left
💡 Hint
Count distinct user_id values.
✗ Incorrect
There are three unique user_ids: u1, u2, and u3.