Answer:
#section 1
data = open('data.txt', 'r')
num = (data.read())
num = num.split()
data.close()
#section 2
for x in num:
x = int(x)
if x < 0:
minus = open('dataminus.txt', 'a')
minus.write(str(x) + ' ')
minus.close()
elif x > 0:
plus = open('dataplus.txt', 'a')
plus.write(str(x)+' ')
plus.close()
Step-by-step explanation:
#section 1
A file data.txt containing an unknown number of lines each containing a single integer is opened.
The data is read from it and split to form a list from which the code will iterate over with a FOR loop and some conditional statements will be used to determine if the number is positive or negative.
#section 2
In this section two new files are created/ opened dataplus.txt and dataminus.txt and all the positive integers are stored in the dataplus.txt and the negative integers in the dataminus.txt.
The IF statement and elif statement used ensures that zero(0) is not captured ensuring that the code fulfills all the requirements in your question.