Drill

ProblemsPython › network

Which HTTP status family does a code belong to

easynetworkPython

HTTP status codes are grouped by their hundreds digit: 2xx means success, 5xx means server trouble, and so on.

http_family(status: int) → int

Solve it in the editor →

Where you start

def http_family(status: int) -> int:
    

Worked examples

CallResult
http_family(200)2
http_family(404)4
http_family(503)5
http_family(100)1

Hint

Divide by 100 and check the result.

Reference solution in Python
def http_family(status: int) -> int:
    if 100 <= status <= 199:
        return 1
    if 200 <= status <= 299:
        return 2
    if 300 <= status <= 399:
        return 3
    if 400 <= status <= 499:
        return 4
    if 500 <= status <= 599:
        return 5
    return 0

The same problem in another language

More network problems in Python