Develop a program to read the name, birthday and gender of a person from a file and output the name and ten-digit national identity card (NIC) number to another file where each name is starting on a new line (see the example below). The only input to the program is the name of the file. The output of the programme is the file "output.txt". Below are the rules for forming the NIC number.
first_file = open("input.txt","w")
#Adding some data to the file
first_file.write("Abraham 01/13/2012 Male\n");
first_file.write("Rose 01/13/2007 Female\n");
first_file.write("John 01/13/2009 Male\n");
first_file.write("Rachel 01/13/2010 Female\n");
first_file.close()
next_file = open("input.txt","r")
list1 = next_file.read()
str1 = list1.split("\n")
n = len(str1)
name = " "
year = " "
for i in range(0,n-1):
first = str1[i].split(" ")
name += first[0] + '\n'
year1 = first[1].split("/")
year += year1[2] + '\n'
print(name+" "+year)
Comments
Leave a comment