Drill

ProblemsC# › network

Which HTTP status family does a code belong to

easynetworkMathC#

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

HttpFamily(status: int) → int

C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

public int HttpFamily(int status) {
    
}

Worked examples

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

Hint

Divide by 100 and check the result.

Reference solution in C#
public int HttpFamily(int status) {
    if (status >= 100 && status <= 199) return 1;
    if (status >= 200 && status <= 299) return 2;
    if (status >= 300 && status <= 399) return 3;
    if (status >= 400 && status <= 499) return 4;
    if (status >= 500 && status <= 599) return 5;
    return 0;
}

The same problem in another language

More network problems in C#