ChatGPT answser
In Sri Lanka, the National Identity Card (NIC) number is derived from the birth date, along with other components such as district and gender codes. The format for a Sri Lankan NIC number is ABBBBBBCD where:
- A: First letter of the last name (in Sinhala or Tamil script)
- BBBBB: Sequential number based on birth date (YYMMDD format)
- C: A checksum digit
- D: Gender code (1 for male, 2 for female)
To convert a birth date to a Sri Lankan NIC number, you would need to follow these steps:
- Extract the components of the birth date: year (YY), month (MM), and day (DD).
- Convert the year, month, and day to YY, MM, and DD respectively.
- Concatenate YYMMDD to form the sequential number part of the NIC.
- Add the checksum digit.
- Add the gender code (1 for male, 2 for female).
- Finally, prepend the first letter of the last name in Sinhala or Tamil script.
Here's an example in Python:
pythonCopy code
def generate_sri_lankan_nic(last_name, birth_date, gender):
# Extracting components of birth date
year = str(birth_date.year)[-2:]
month = '{:02d}'.format(birth_date.month)
day = '{:02d}'.format(birth_date.day)
# Generating sequential number (YYMMDD)
sequential_number = year + month + day
# Calculating checksum digit
checksum = 0
for i in range(len(sequential_number)):
checksum += int(sequential_number
) * (9 - i)
checksum %= 10
# Determining gender code
gender_code = '1' if gender.lower() == 'male' else '2'
# Generating NIC number
nic_number = last_name[0] + sequential_number + str(checksum) + gender_code
return nic_number
# Example usage
last_name = "මාර්තු"
birth_date = datetime.date(1990, 5, 15) # Example birth date
gender = "male" # Example gender
nic_number = generate_sri_lankan_nic(last_name, birth_date, gender)
print("Sri Lankan NIC Number:", nic_number)
Replace the last_name, birth_date, and gender variables with the appropriate values. This script will generate a Sri Lankan NIC number based on the given information.