Problem · Medium · 25 min
Check an IPv4 address
- Medium
- Parsing text
- Strings
An IPv4 address has four numbers that are separated by dots, for example 192.168.0.1.
Write is_valid_ipv4(text). It returns True when the text is a valid address, and False when it is not. A valid address follows all of these rules:
- It has exactly four parts, separated by
.. - Each part is not empty, and it has only the digits
0to9. It has no sign, no space and no other character. - Each part is a number from 0 to 255.
- A part has no leading zero.
0is fine, but01and007are not.
Examples
| Call | Result |
|---|---|
is_valid_ipv4('192.168.0.1') |
True |
is_valid_ipv4('256.1.1.1') |
False |
is_valid_ipv4('1.2.3') |
False |
Tasks
2 to do
Task 1, not checked yet. Make
is_valid_ipv4pass the example tests.Task 2, not checked yet. Make
is_valid_ipv4pass the hidden tests.
Task 1 of 2
Make is_valid_ipv4 pass the example tests.