10.2k views
5 votes
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

1 Answer

6 votes

Answer:

Step-by-step 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('\\', '').split(';')

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

f_output.write(line)

print(line)

f_output.close()

Starting from the input.Txt file which contains surname, name and age separated by-example-1
User Kamil Klimek
by
3.8k points