Pincode Details Finder

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, a…


This content originally appeared on DEV Community and was authored by Vidya🌞

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:


This content originally appeared on DEV Community and was authored by Vidya🌞


Print Share Comment Cite Upload Translate Updates
APA

Vidya🌞 | Sciencx (2026-04-20T06:06:58+00:00) Pincode Details Finder. Retrieved from https://www.scien.cx/2026/04/20/pincode-details-finder/

MLA
" » Pincode Details Finder." Vidya🌞 | Sciencx - Monday April 20, 2026, https://www.scien.cx/2026/04/20/pincode-details-finder/
HARVARD
Vidya🌞 | Sciencx Monday April 20, 2026 » Pincode Details Finder., viewed ,<https://www.scien.cx/2026/04/20/pincode-details-finder/>
VANCOUVER
Vidya🌞 | Sciencx - » Pincode Details Finder. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2026/04/20/pincode-details-finder/
CHICAGO
" » Pincode Details Finder." Vidya🌞 | Sciencx - Accessed . https://www.scien.cx/2026/04/20/pincode-details-finder/
IEEE
" » Pincode Details Finder." Vidya🌞 | Sciencx [Online]. Available: https://www.scien.cx/2026/04/20/pincode-details-finder/. [Accessed: ]
rf:citation
» Pincode Details Finder | Vidya🌞 | Sciencx | https://www.scien.cx/2026/04/20/pincode-details-finder/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.