Practice

Problem 6 of 10

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 0 to 9. 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. 0 is fine, but 01 and 007 are 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

  1. Task 1, not checked yet. Make is_valid_ipv4 pass the example tests.

  2. Task 2, not checked yet. Make is_valid_ipv4 pass the hidden tests.

Task 1 of 2

Make is_valid_ipv4 pass the example tests.

All tasks

main.py

Ctrl+Enter runs your code. Ctrl+Shift+Enter runs all the tests. Press Esc, then Tab, to leave the editor.

Output

Press Run to see your result

Your output shows here. Press Run to try your code.