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
Examine the exhibit above. "Device A" is an 8-port layer 2 managed switch and "Device C" is a 4-port hub. Which of the following
Harlamova29_29 [7]

Answer:

Device B is Router.

Explanation:

Router is the device that is used to connect different networks to communicate with each other to make possible for all devices of all networks to communicate with each other that are connected to that particular network.

In above case, Device A is 8 port switch that makes a network of 8 different computers. Device C is a 4 port hub that is connected with 4 computers. Both Device A and Device C are different Networks, router is used to connect both all devices of both networks so that they can communicate each other. So the Device B should be router.

6 0
2 years ago
A.Distance sensor<br> b.Programable microcontroller<br> c.Ambient light sensor<br> d.Wi-Fi
Rainbow [258]

D WiFi

It uses wifi to connect to the internet

3 0
2 years ago
Read 2 more answers
Using a linear search to find a value that is stored in the last element of an array of 20,000 elements, ________ element(s) mus
Klio2033 [76]

Using a linear search to find a value that is stored in the last element of an array of 20,000 elements, 20,000 element(s) must be compared.

6 0
1 year ago
If you are uploading files you plan to edit online, you will need to convert them to Google Drive format. T or F
Amiraneli [1.4K]

Answer:

save as a word document (.docx) to keep editing offline then copy and paste into the google doc

5 0
2 years ago
What is a way to minimize technical problems with your computer
Gala2k [10]
Buy or get new software that protects ur pc, such as a "fixmestix" or just download new software or use a disc 
4 0
3 years ago
Other questions:
  • Which css property configures the capitalization of text?
    12·1 answer
  • When creating a software package, the software must be designed, the code must be written, and then the code must be tested. Thi
    6·1 answer
  • OSI is a seven-layered framework used to help define and organize the responsibilities of protocols used for network communicati
    6·1 answer
  • HELP AS SOON IS A UNIT TEST WILL GIVE BRAINLIEST
    9·2 answers
  • Match each language to its use.
    7·1 answer
  • In general, digital to analog modulation equipment is less expensive than the equipment for encoding digital data into a digital
    8·1 answer
  • Which of the following is one of the tools in REPL.it that helps prevent syntax errors?
    10·1 answer
  • How can you reduce the Impact of Hacking? <br>pls help with this &lt;3​
    9·1 answer
  • What is this....... Iam booking train to patna. ​
    13·2 answers
  • What is an aspect ratio?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!