Regular expressions · 9 / 15 Exercise Easy

Postal code

Objective

Create a Python program that validates postal codes with re.fullmatch.

Instructions

  • Read an integer n and then n codes, one per line.
  • A postal code is valid if it is made up of exactly 5 digits: r"\d{5}".
  • Use re.fullmatch, which requires the whole text to match (not just a part of it).
  • Show Valid or Not valid for each code, in the same order.
Input
4
28001
2800
280011
2800a
Output
Valid
Not valid
Not valid
Not valid

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise