from datetime import datetime
file_name = input()
file1 = open(file_name, 'r')
Lines = file1.readlines()
count = 0
year_prev = 0
NIC_Code = []
f = open("output.txt", "r+")
f.truncate(0)
for line in Lines:
words = line.split()
if year_prev==0:
year_prev= words[1].split("-")[0]
if year_prev != words[1].split("-")[0]:
count = 0
count += 1
nic = ''
nic=nic+words[0]
start_date = str(words[1].split("-")[0])+"-01-01"
days = ((datetime.strptime(words[1],"%Y-%m-%d") - datetime.strptime(start_date,"%Y-%m-%d")).days)+1
if words[2]=="F":
nic=nic+str(days+500)
else:
nic=nic+str(days)
if count<10:
nic=nic+"00"+str(count)
elif count>=10 and count<100:
nic=nic+"0"+str(count)
else:
nic=nic+str(count)
print(nic)
year_prev = words[1].split("-")[0]
f.write(words[0]+" "+nic+"\n")
f.close()
Sample Input
task1.txt
Saman123001
Aruni596002
One file "output.txt" will be saved.
Comments
Leave a comment