1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ne4ueva [31]
3 years ago
14

A file named data.txt contains an unknown number of lines, each consisting of a single integer. Write some code that creates two

files, dataplus.txt and dataminus.txt, and copies all the lines of data1.txt that have positive integers to dataplus.txt, and all the lines of data1.txt that have negative integers to dataminus.txt. Zeros are not copied anywhere.
Computers and Technology
2 answers:
slavikrds [6]3 years ago
6 0

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()

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.

Damm [24]3 years ago
3 0

Answer:

I am doing it with python.

Explanation:

nums = '9 -8 -7 -6 -5 -4 -2 0 1 5 9 6 7 4'

myfile = open('data.txt', 'w')

myfile.write(nums)

myfile.close()

myfile = open('data.txt', 'r')

num1 = (myfile.read())

num1 = num1.split()

print(num1)

print(type(num1))

for x in num1:

   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()

You might be interested in
Which of these is a discipline?
ivolga24 [154]

Answer: Information technology

Nanotechnology

Explanation:

Database Managers are the individuals who responsible create databases for organizations and maintain existing ones.

Nanotechnology simply refers to a research field that has to do with the building of things and devices.

Information technology refers to the study of computers for the storage and sending of information.

A network technician is someone who maintains, and repairs computer systems and they also set up several Internet connections, and networks.

We should note that information technology and nanotechnology are both disciplines as they are studied in different colleges.

3 0
3 years ago
Power brakes:
IgorLugansk [536]
The answer is B becausePower brakes are a system of hydraulics used to slow down or stop most motor vehicles. It uses a combination of mechanical components to multiply the force applied to the brake pedal by the driver into enough force to actuate thebrakes and stop a vehicle that can weigh several tons.
5 0
4 years ago
Read 2 more answers
What does Falstaff do to protect himself in battle? ​
notka56 [123]
Bark bark bark bark bark bark bark bark bark bark bark bark bark bark bark bark bark bark bark bark bark bark bark
3 0
3 years ago
In a contract, what is consideration
Mrac [35]
Do you wan the definition ?
3 0
3 years ago
What happens when your computer is in hibernate mode??
Alina [70]
I think hibernate is sort of like sleep mode. It puts your computer on low battery, but it's not turn off. And some unsaved information doesn't get erase.
6 0
3 years ago
Read 2 more answers
Other questions:
  • What is the full form of IE? ​
    9·1 answer
  • QUICK ANSWER- what is the function of GUI
    6·2 answers
  • What is top down design? a. Top down design is a way of designing your program by starting with the biggest problem and breaking
    7·1 answer
  • Write a loop that sets each array element to the sum of itself and the next element, except for the last element which stays the
    15·1 answer
  • Good ways to increase sales on phone accesories?
    10·2 answers
  • What are the disadvantages of using photo editing software in photography?
    14·1 answer
  • What is an infodemic?
    10·1 answer
  • Which of the following is the best example of an installation issue
    11·2 answers
  • Lloyd has created a validation script for a data entry form. What property should he use to test for a selected radio button?
    7·2 answers
  • Why are men more exposed to mass media?
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!