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
Numeric data is stored in ___________ for direct processing.String variablesBNumeric variablesCOutputDText
zimovet [89]

We need answer choices

4 0
3 years ago
Who made the first sandwich?
RoseWind [281]
That guy made it. john m the 4th

7 0
3 years ago
Read 2 more answers
The concept that involves combining or associating individual elements of unclassified information to reveal an additional assoc
lozanna [386]

Answer:

Classification by compilation. It is when you take two or more pieces or unclassified information and put them together in a way that discloses classified information. Similarly, you can apply this to items of information that are classified at a specified level, but when combined, becomes classified at a higher level.

Explanation:

7 0
4 years ago
LATHAN ( asas sains komputer form 3)
a_sh-v [17]

Answer:

Wut

Explanation:

Wut

7 0
3 years ago
FIRST TO ANSWER RIGHT GETS BRAINLIEST!!!!! Which of the following sets of data would be represented best in a histogram?
hjlf

Answer:

b

Explanation:

I think it would be B. The average monthly sales for the big toy company because its giving data over history

8 0
3 years ago
Other questions:
  • Dinah is using an I.D.E to write, modify, and save code. Which tool should she use?
    8·2 answers
  • Which option is a form of an assistive technology?
    7·1 answer
  • Digital Photography Help please
    9·2 answers
  • Which visual aid would help a group of veterinary students study a dog's anatomy?
    14·1 answer
  • There is an enormous amount of information on the Internet that is automatically separated into good content and not-so-good con
    15·1 answer
  • How many syllables does snail have
    12·1 answer
  • Which is a method used with arrays?<br><br> find<br><br> index<br><br> insert<br><br> sort
    8·1 answer
  • What are the determinants of price elasticity of demand?​
    11·2 answers
  • Complete the program below named CountVowels so that it reads in a string, counts all the vowels in that string, and prints out
    13·1 answer
  • Which three staements about gravity and the formation of the solar system are true?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!