0

Our teacher has told us to make a program that validates a postcode as a Northern Ireland postcode. That means it must have the letters "BT" in it and must equal 8 characters. In the code below I managed to get the letters part working. However, he did not go into detail on how to make the input equal 8 characters. He mentioned using .length() and validation(try and except), but I'm unsure how to use .length() to get 8 characters. Here's my code:

postcode = input("Please enter an Northern Ireland postcode:")
BT = "BT"
while BT not in postcode:
    postcode = input("That isn't a Northern Ireland postcode. Try again:")
print("This is a Northern Ireland postcode")

1 Answers1

0

To get the number of characters in a String, you can use len(postcode).

lo2ndii
  • 75
  • 6
  • Here is a link to the documentation regarding `len()`: https://docs.python.org/3/library/functions.html#len – lo2ndii Feb 26 '17 at 16:56