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
Leno4ka [110]
3 years ago
6

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:
dmitriy555 [2]3 years ago
8 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()

yuradex [85]3 years ago
8 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.

You might be interested in
What is the name of the technology that integrates vast data bases with georeferenced data in order to design, plan, and manage
ivanzaharov [21]

Answer:

"Geographic information systems " is the right answer.

Explanation:

  • This is indeed a computer-based method for observing and analyzing current events that are happening on the planet. GIS could enhance teaching and learning begin to understand geographical trends and regularities by relaying completely unconnected information.
  • It represent an experimental field and while the GIS supplier government offers us modern, improved, and quicker technical resources for the computer hardware.
7 0
3 years ago
1 byte =???? bit<br> please help me
diamong [38]

Answer:

8 bits make a byte

Explanation:

8 bits make a byte

7 0
2 years ago
Why did artists use pinhole cameras during the renaissance?
Dima020 [189]
Pinhole cameras were one of the most sophisticated devices of the period, it made tasks much easier it basically worked exactly like the human eye and is something just like tracing.
8 0
3 years ago
Your boss asks you to transmit a small file that includes sensitive personnel data to a server on the network. The server is run
mel-nik [20]

Answer:

a. Telnet transmissions are not encrypted.

Explanation:

Indeed, since <em>Telnet transmissions are not encrypted,</em> all the information sent, and even the characters typed in the telnet console are sent in clear text.

This is a security issue, since any other device in the same network will receive a copy of the information (packets) sent. For default, all the devices, except for the server expecting to receive the information, will discard the packets. However it is easy to actively <em>listen </em>and keep those packets, wich will contain the information in plain text and human readable.

4 0
3 years ago
Adding _______ around calculations indicates which calculations should be performed first before following the typical order of
Finger [1]

Adding parenthesis around calculations indicates which calculations should be performed first before following the typical order of operations. Correct answer: DThe order of operations is the order in which all algebraic expressions should be simplified is the following: First should be calculated expressions with parentheses, then exponents (and Roots) means power , then multiplication & Division and at the end Addition & Subtraction.

5 0
3 years ago
Read 2 more answers
Other questions:
  • Why do contour lines never cross?
    5·1 answer
  • The ability to anticipate and determine upcoming driving hazards and conditions are adversely affected
    14·1 answer
  • Which institution developed outside the limits of the written costitution of the united states ?
    14·1 answer
  • All of the following can be caused by the movement of geologic plates EXCEPT
    15·1 answer
  • Create a spreadsheet that lists the ten currencies you chose. For each currency, enter an amount and create a
    12·1 answer
  • How many nibbles make one kilobyte​
    7·2 answers
  • _____ is the practice of using the internet to provide healthcare without going to a doctor’s office or hospital.
    15·2 answers
  • Explain Http and Ftp​
    12·1 answer
  • The other term for template document is _______.
    13·2 answers
  • Difference between hacking and cracking not hackers and crackers ​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!