Starting from the input.Txt file which contains surname, name and age separated by a semicolon, write in the output.Txt file surname, name and age separated by semicolons only for students of age

Respuesta :

Answer:

Explanation:

The following code was written in Python. Since no actual age was given in the question I created a function that takes in the age as a parameter. It then loops throught all of the entries in the input.txt file and selects only the ones that have the age higher than the passed argument and writes it to the output file. The code and both the input.txt and output.txt files can be seen in the image below.

def printCSV(age):

   f = open("input.txt", "r")

   f_output = open("output.txt", "w")

   for line in f.readlines():

       line_split = line.replace(" ", '').replace('\n', '').split(';')

       if int(line_split[2]) >= age:

           f_output.write(line)

           print(line)

   f_output.close()

Ver imagen sandlee09