Bird
0
0

Identify the error in this per-user rate limit check pseudocode:

medium📝 Debug Q6 of 15
Rest API - Rate Limiting and Throttling
Identify the error in this per-user rate limit check pseudocode:
requests = {"alice": 3}
limit = 5
user = "bob"
if requests[user] > limit:
    block()
else:
    allow()
ASyntax error in if statement
BKeyError because 'bob' is not in requests dictionary
CLimit comparison uses wrong operator
DNo error, code works fine
Step-by-Step Solution
Solution:
  1. Step 1: Check dictionary keys

    requests dictionary has only "alice", but code accesses requests["bob"].
  2. Step 2: Identify error type

    Accessing a missing key causes a KeyError at runtime.
  3. Final Answer:

    KeyError because 'bob' is not in requests dictionary -> Option B
  4. Quick Check:

    Missing key access = KeyError [OK]
Quick Trick: Check if user key exists before access [OK]
Common Mistakes:
  • Assuming all users exist in requests
  • Ignoring runtime errors
  • Confusing syntax errors with runtime errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes