Fetching latest headlines…
Pincode Details Finder
NORTH AMERICA
🇺🇸 United StatesApril 20, 2026

Pincode Details Finder

0 views0 likes0 comments
Originally published byDev.to

Pincode Details Finder (Python Program)
This program takes a 6-digit pincode as input and validates whether it is correct or not. It extracts the first digit, first two digits, and first three digits to identify the region, sub-region, and district. Using predefined lists, it matches these digits to their respective names. Finally, it displays the location details if valid, otherwise shows an error message.

regions = [
    "1-Delhi",
    "2-Uttar Pradesh & Uttarakhand",
    "3-Rajasthan & Gujarat",
    "4-Maharashtra",
    "5-Andhra Pradesh & Telangana",
    "6-Tamil Nadu & Kerala",
    "7-West Bengal & North East",
    "8-Bihar & Jharkhand",
    "9-Army Postal Service"
]

sub_regions = [
    "11-Delhi Region",
    "40-Mumbai Region",
    "60-Chennai Region",
    "70-Kolkata Region"
]

districts = [
    "110-Delhi", "111-Delhi (North)", "112-Delhi (South)",
    "400-Mumbai", "401-Mumbai (Suburban)", "402-Mumbai (West)",
    "600-Chennai", "601-Tiruvallur", "602-Kanchipuram",
    "700-Kolkata", "701-Kolkata (North)", "702-Kolkata (South)"
]

def check_key(key, data_list):
    i = 0
    while i < len(data_list):
        parts = data_list[i].split("-")
        if parts[0] == str(key):
            return parts[1]
        i += 1
    return None

def pincode_details():
    pincode = input("Enter 6-digit Pincode: ")

    if len(pincode) != 6 or pincode.isdigit() == False:
        print("Invalid Pincode! Pincode must be 6 digits.")
    else:
        pincode = int(pincode)

        first_digit        = pincode // 100000
        first_two_digits   = pincode // 10000
        first_three_digits = pincode // 1000

        region    = check_key(first_digit, regions)
        subregion = check_key(first_two_digits, sub_regions)
        district  = check_key(first_three_digits, districts)

        if region:
            print("\nValid Pincode ")
            print("Region     :", region)
            print("Sub-region :", subregion if subregion else "Unknown Sub-region")
            print("District   :", district if district else "Unknown District")
        else:
            print("Invalid Pincode ")

pincode_details()

output:

Comments (0)

Sign in to join the discussion

Be the first to comment!