Answer to Question #243899 in Python for ush

Question #243899

Develop a program to read the namebirthday 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.

  • The first four digits of the ID card is the birth year.
  • The next three 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 in the order of submission for a particular birth year. 
  • The input file contains the records in the order of submission where each attribute is space-separated.
  • In the example given below, Aruni is the second entry in the year 1990. Therefore the last three digits of the NIC are 002.
  • Assume there are only 999 entries per year.
1
Expert's answer
2021-09-29T01:32:38-0400






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)

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