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
Cyber security class i need help​
makkiz [27]

Answer:

Explanation:

yooooo it b

5 0
3 years ago
What percent<br> of students in<br> the US are<br> considered<br> ESL<br> students?
mariarad [96]

Answer: 9.5%

Explanation: There were nearly 5 million English language learners in U.S. public schools in fall 2015, according to the most recent available data from the National Center for Education Statistics. This represented 9.5% of U.S. public school enrollees, an increase from 8.1% in 2000

5 0
3 years ago
c programming Write code that prints: Ready! countNum ... 2 1 Go! Your code should contain a for loop. Print a newline after eac
olga_2 [115]

Answer:see explanation

Explanation:

Hello, from your question I see that you need a program which based on countNum's value prints ready then all the numbers to 1 and finally go!, I'd appreciate if you provided information about the numbers after the example you gave as I do not know if they are to be printed too.

The solution I provide includes the countdown to 1 printing newline after each number and text. Try it out!

#include <stdio.h>

int main(void)

{

   int countNum;

   int i;

   countNum = 22;

   for ( i = countNum; i > 0; i--) {

       if (i == countNum){

           printf("Ready!\n");

       }

       printf("%d\n",i);

   }

   printf("Go!\n");

   return 0;

}

6 0
3 years ago
Lots of data can be transferred in short time, when we have,
dusya [7]

Answer: B. Higher Bandwidth

8 0
2 years ago
Read 2 more answers
You want high availability for DHCP services, a primary server to handle most DHCP requests, and a secondary server to respond t
babymother [125]

Answer:

The blocking system.

Explanation:

In order to avoid servers to replicate with each other, I should configure the blocking system of the first DHCP.

For example, if the first DHCP fails to respond, the second will get in place, however, I have to configure the first system that immediately that the second DHCP starts working, the first blocks its information and use.

By this way, there won´t be any duplicated actions or reponses.

5 0
3 years ago
Other questions:
  • The concept of vertical farming allows agriculture to occur when there is not enough___Available .
    13·1 answer
  • If you have cable internet service, what protocol is used between the head end connection and the cable company's network
    8·1 answer
  • Write only in C, not C++.
    14·1 answer
  • PLEASE HELP ASAP!!! 99 POINTS FOR 3 MULTIPLE CHOICE QUESTIONS!!! PLEASE ANSWER ALL!!!
    8·1 answer
  • Not all hardware is connected with wires, some hardware might be connected wirelessly with
    9·1 answer
  • Who play fortnite gameeeeeeee
    14·1 answer
  • Adobe Indesign project 4 museum indesign file. The instructions are 70 pages long I cant sit still long enough to read them
    11·1 answer
  • Please Help ASAP. Marking Brainliest For Correct Answer.
    5·1 answer
  • What is a sensitive compartmented information program
    12·1 answer
  • The implementation stage of the SDLC is when the system is moved into operation where it can be used. What stage PRECEDES the im
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!