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
How many address bits are needed to specify each byte in a 512 byte memory unit?
schepotkina [342]

Explanation:

In a 512 byte memory unit, in order to address each byte, there will be 512 locations (each one byte) ranging from 0 to 511.

Thus it will take 9 bits (2^9=512) to store the address within the unit.

5 0
3 years ago
Which type of loop only runs while a condition is true?
Oksanka [162]

Here is some ranting.

You haven't specified programming language. And every type of loop runs only when a condition is true (that is the definition of a loop).

And here is the answer.

Well, there is [code]for[/code], [code]while[/code] and in some languages even [code]do while[/code].

Hope this helps.

3 0
3 years ago
Read 2 more answers
Which command on the Insert tab of the PowerPoint Online application is used to add a Venn diagram or process chart to a present
Setler [38]

The command to add a Venn Diagram or a process chart on PowerPoint Online is to select the Insert tab, then select the SmartArt button, and there is the process charts listed under Process. But the Venn Diagram is listed under List.

7 0
3 years ago
Read 2 more answers
season is when the weather is not optimal and few tourists of vacation time a shoulder b high c average d low​
cricket20 [7]
Winter is such a season. Travel is lower to colder climate areas such as Canada, but higher to warmer climate areas like Columbia.
7 0
3 years ago
Read 2 more answers
Write a MIPS assembly language program that
8_murik_8 [283]

Answer:

123456789098765432

Explanation:

asdfghjklokjhgfdsasertyujn nbgfdfvbnjujhgvfcdec vgfredfghjmk

5 0
3 years ago
Other questions:
  • True or False. It is required to restart the client computer after the DLP agent has been installed.
    9·2 answers
  • Print either "Fruit", "Drink", or "Unknown" (followed by a newline) depending on the value of userItem. Print "Unknown" (followe
    15·1 answer
  • 1. Write a program to prompt the user to enter a single character and respond back whether or not the character is valid dna. 2.
    12·1 answer
  • Juliet is trying to increase her savings account and she decides that she is going save an additional $700 every month. If her m
    9·1 answer
  • Which ipv6 prefix will the typical enterprise network receive from the service provider?
    12·1 answer
  • Three variables, x, y and z, supposedly hold strings of digits, suitable for converting to integers. Write code that converts th
    7·1 answer
  • What category of sensory receptors are sensitive to touch sound and motion?
    10·1 answer
  • ________ are chunks of software - installed on one's computer, tablet, or smartphone - that are gateways to games, online resour
    8·1 answer
  • Will, there be any presents this year
    15·1 answer
  • Need help ASAP.<br> I am so lost.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!