Bird
Raised Fist0

Given this code snippet for per-IP rate limiting:

medium📝 Predict Output Q4 of Q15
Rest API - Rate Limiting and Throttling
Given this code snippet for per-IP rate limiting:
requests = {"192.168.1.1": 4, "10.0.0.2": 2}
limit = 3
ip = "192.168.1.1"
if requests[ip] > limit:
    print("Blocked")
else:
    print("Allowed")

What is the output?
ABlocked
BError: Key not found
CAllowed
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Check requests count for IP

    requests["192.168.1.1"] is 4, which is greater than limit 3.
  2. Step 2: Evaluate condition and output

    Since 4 > 3, the code prints "Blocked".
  3. Final Answer:

    Blocked -> Option A
  4. Quick Check:

    requests[ip] > limit = True, output = Blocked [OK]
Quick Trick: Compare requests[ip] to limit to decide [OK]
Common Mistakes:
MISTAKES
  • Assuming less than or equal blocks
  • Confusing IP keys
  • Ignoring dictionary values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes