Answer to Question #246330 in Python for Hiruni

Question #246330
Develop a program to read the name, birthday and gender of a person from a file and output the name and ten-digit identity card (NIC) number to another file , each name starting on new line (see
example below)The only input to the program is the name of the file. output is the file "output.txt".
rules
The first 4 digits of the ID card is the birth year.
The next 3 digits are the number of days to the birth date from January 1st of that year. If the person is a female, 500 is added to that value.
The next three digits are assigned to submission for a particular birth year. input file contains the records of submission where each attribute is space separated.
In example , Aruni is the second entry in year 1990. Therefore the last three digits of NIC are 002.Assume there are only 999 entries per year.
Example:
Input file output file
Saman 1990-05-03 M Saman 1990123001
Aruni 1990-04-06 F Aruni 1990596002
Nazar 1997-09-24 M Nazar 1997267001
1
Expert's answer
2021-10-04T12:43:19-0400
from datetime import date


infile   = open("H:\\Input.txt","r")
outfile  = open("H:\\Output.txt","w")
lineRead = (infile.read()).split("\n")
infile.close()
yr  = []
for r in range(0,len(lineRead)):
    ID=""
    temp = lineRead[r].split(" ")
    s = temp[1][0]+ temp[1][1]+temp[1][2]+temp[1][3]
    y = int(s)
    yr.append(y)
    m = int(temp[1][5]+temp[1][6])
    d = int(temp[1][8]+temp[1][9])
    d0 = date(y, 1, 1)
    d1 = date(y, m, d)
    delta = d1 - d0
    t = delta.days+1
    Cnt = yr.count(y)
    if(Cnt<10): c = "00"+str(Cnt)
    if(Cnt>9 and Cnt<100): c = "0"+str(Cnt)
    if(Cnt>99): c = str(Cnt)
    if(temp[2]=='F' or temp[2]=='f'):
        t = t+500
    ID = ID + str(y) + str(t) + c
    print("%s\t%s\t%s\t%s\n"%(temp[0],temp[1],temp[2],ID))
    outfile.write("%s\t%s\t%s\t%s\n"%(temp[0],temp[1],temp[2],ID))
outfile.close()    




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS