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
A c++ member function that uses, but does not change, the value of a member variable is called
Elina [12.6K]
Call by reference.

Hope this helps
5 0
3 years ago
What is the best approach to testing a website? visit all pages to verify that they load visit every page and verify all links v
shusha [124]

Answer:

B, visit every page and verify all links

Explanation:

6 0
2 years ago
What is the output of the following program? #include using namespace std; class TestClass { public: TestClass(int x) { cout &lt
Alik [6]

Answer:

An error will be occurred here. In C++ a function must be like

returntype function_name(){

}

but the functions in given class does not have returntype given. So there will be a syntax error.

If the returntype is defined then the code does not show any output since nothing is printed in the main function.

4 0
3 years ago
"Explain the functionality of the different layers found in the network protocol stack of an operating system such as Linux"
arsen [322]

Answer:

There are 7 layers in linux.

Explanation:

As networking is difficult and complex.

Imagine if every application had to know how to communicate on every step that would be more than just complex. So, rather than reinvent something which will help it to communicate let’s just make something that will automatically controls the communication and for that protocols came in to live.

As for the linux operating system, it is not exceptional from other operating systems.

There are 7 layers on network protocol stack use to communicate with other network protocol stack.

1. Application layer

2. System call interface

3. Protocol agnostic interface

4. Network protocol

5. Device agnostic interface

6. Device drivers

7. Physical hardware

All the layers vary in their functionality.

One more important thing to remember is that the network protocol stack layers is not one way its 2 way communication. First, when a client request to a network and second, when the request is full filled.

The top most layer is a part of user space, the next five layers comes in the kernel space and the final layer is the physical layer.

<u>Application layer: </u>

When a client or user request to  a network the request initially comes to this layer.

On this layer we use tcp/ip protocol.

<u>System call interface(SCI): </u>

When application layer make a call to the kernel this layer handles that call. And take the request to the next layer.

<u>Protocol agnostic interface: </u>

This layer has two functions “talking” or “listening”. There is a thing called sockets which perform these functions and each socket has an id which is used specifically for an application.

<u>Network protocol: </u>

This layer is used for how the data is sent or received.

<u>Device agnostic interface: </u>

It is used to connect data from/to kernel user space and the network device drivers which allows the data to prepare itself for transmission over the medium from the network device.

<u>Physical hardware : </u>

This layer is responsible for the data packets transmission and received from the network medium being used whether cable or wireless.

5 0
3 years ago
Which of the following roles is responsible for creating cloud components and the testing and validation of services?
DanielleElmas [232]

Answer:

The correct answer to the following question will be Option D (Cloud service developer).

Explanation:

  • Developers are usually individuals who layout and build applications or websites such as web or software systems. They would be known as app or web developers in this regard. In the sense that they still build and maintain things, a software developer is quite similar, however-and here's the deciding factor-this is achieved on virtual clouds.
  • It is the responsibility of the cloud service developer to design and build cloud elements and products, as well as to check and validate services.

Therefore, Option D is the right answer.

7 0
3 years ago
Other questions:
  • With network management software, a network manager can ____.
    6·1 answer
  • What formatting option is easiest to read when printed out
    12·1 answer
  • What do you call a named collection of data stored on a disk?
    15·1 answer
  • In the space below, write the formula that needs to be added to the blank cells under the fourth column of the table.
    13·1 answer
  • A5.3 1012 kg satellite is 1,800 m from another satellite that has a mass of 3.5 x 108 kg. What is the gravitational
    6·1 answer
  • Public static String doSomething(String s) { final String BLANK = " "; //BLANK contains a single space String str = ""; //empty
    6·1 answer
  • What are the defenses to protect against these attacks?
    13·1 answer
  • The type of medium used to hide data in steganography is referred to as __________. This may be a photo, video, sound file, or V
    12·2 answers
  • What is the importance of effectiveness in communication?
    14·1 answer
  • Text Questions
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!