Route on Status Codes

Easy ⏱ 8 min 82% acceptance ★★★★★ 4.8
Write classify_response(status) mapping an HTTP status integer to 'success' (2xx), 'redirect' (3xx), 'client-error' (4xx), 'server-error' (5xx) or 'unknown' — integer division by 100 beats a lookup table of every code.

Examples

Example 1
Input
classify_response(201)
Output
'success'
Explanation

201 Created is in the 2xx family.

Example 2
Input
classify_response(503)
Output
'server-error'
Explanation

5xx means the server failed.

Constraints

  • Family-based classification.
  • Out-of-range values → 'unknown'.

Topics

APIsstatus codes

Companies

PostmanTwilioSendGrid

Hints

Hint 1

status // 100 gives the family digit.

Hint 2

A dict maps 2/3/4/5 to the labels.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.