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 terms describes Benito Mussolini’s form of government
slega [8]
The political system that describes Benito Mussolini’s form of government would be totalitarian.Hope this answers the question:)
5 0
4 years ago
Read 2 more answers
If I wanted to repeat an action such as a heading for a paper, it would be helpful to _____.
NemiM [27]
Possibly rephrase or rewrite the heading or whatever else you decide to repeat. You should never say the exact thing twice. 
Hope I helped :)
7 0
3 years ago
Read 2 more answers
A ______ workstation is a network terminal that supports a full-featured user interface, but limits the printing or copying of d
Sladkaya [172]

Answer: The answer is a diskless workstation.

3 0
3 years ago
Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and the minimum value to minMile
lina2011 [118]

Answer: 40, 4

Explanation:

8 0
3 years ago
Four friends bought three same-sized pizzas for dinner.
o-na [289]

Answer:

9/8 of a pizza

Explanation:

3/4 -> 6/8

1/2 -> 4/8

5/8 -> 5/8

We can now add all of these:

6/8 + 4/8 + 5/8 = 15/8

The total amount of pizza is 24/8 because there are 3 pizzas.

24/8 - 15/8 = 9/8

6 0
4 years ago
Other questions:
  • Ally made the net below to find the surface area of a box she was designing. The box measures 12 centimeters long by 9 centimete
    7·1 answer
  • Ms Access is spreadsheet software.True or false​
    9·2 answers
  • What does the use of color and images on a blog refer to?
    10·2 answers
  • 2. Billys teacher asked him to type a report about asian food. Which paragraph format should he use?
    12·2 answers
  • Which tasks can be completed using the Chart Tools Design tab? Check all that apply.
    9·1 answer
  • The data-linking feature that allows Internet users to skip directly from a highlighted word to a related file in another comput
    12·2 answers
  • Discuss the economical challenges in software reuse using suitable examples.
    10·1 answer
  • Phân tích vai trò của các yếu tố trong biên tập Audio và Video
    13·1 answer
  • PLZ ANSWER QUICKLY!!
    12·1 answer
  • My computer is being weird, Everytime I begin to type something on here it keeps adding a letter to the beginning of my sentence
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!