answer.
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]
2 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]2 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]2 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
Iris called the company’s security hotline. The hotline is an anonymous way to report suspi- cious activity or abuse of company
marishachu [46]

Answer 1 :

if Iris had approached Henry, it might had become a personal matter rather than professional. Following the proper protocol is the best way to report in any organization.

Answer 2 :

Yes, Gladys should call the legal authorities. Federal Trade Commission (FTC) is the best agency to file a complaint prevention of corruption within a company.

Answer 3 :

Yes, she should have followed her chain of command because that is one of the many questions that an investigator will ask is if she reported it to her supervisor and human resources. Somehow in companies they use that term when it is somewhat of a legal issue. Internally if she knew the IT director and the security office she could have gone to them along with human resources. Outside I would say start with her local police department and they may have directed her to the proper channel.

Answer 4 :

What Henry did was not ethical even in the slightest. He used the flash drive without permission from the company, he knew he shouldn’t have, but he did it anyway. It is acted in a complete ethical way. If Iris had left this in a coffee station and forgot about it, then it would have been unethical behavior because she knew about it but didn’t whistle blow. There are security laws that get violated in this issue which is why it is unethical and troublesome.

5 0
2 years ago
Of the following tasks, which one CANNOT be easily accomplished with a Wiki? Collaborating Social networking Editing Reading
jeka94
Social networking.... pretty much all wikis let u edit of course u can read them and collaborating easy enough.... social networking not possible
4 0
2 years ago
Some early computers protected the operating system by placing it in a memory partition that could not be modified by either the
Sav [38]

Answer:

Check the explanation

Explanation:

1. Such operating systems cannot be modified and updating such OS (operating systems) would be almost impossible. This can prove fatal if we detect some serious bug, since there is no way to correct it.

2. The entire password and other credentials of users must be kept in an unsecure and vulnerable memory, since we can’t store it in the protected memory.

5 0
2 years ago
Consider a DHT with a mesh overlay topology (that is, every peer tracks all peers in the system). What are the advantages and di
Vladimir79 [104]

Answer:

Advantages of DHT with mesh overlay topology

  • A single hop is used to route a message to the peer, the nearest key is used route message between points
  • There are  bi-directional links between each pair of peers other than the broadcasting peer therefore creating a multiple delivery paths from source to other peers

Disadvantages of DHT with mesh overlay topology

  • complexity of the design of a Mesh overlay Topology
  • Consuming process ( tracking of all peers by each peer )

Advantages of circular DHT ( with no shortcuts )

  • less consuming process ( each peer tracks only two peers )

Disadvantages of Circular DHT ( with no short cuts )

  • The number of messages sent per query is minimized
  • 0(N) hopes are required to route message to a peer responsible for the key  

Explanation:

Advantages of DHT with mesh overlay topology

  • A single hop is used to route a message to the peer, the nearest key is used route message between points
  • There are  bi-directional links between each pair of peers other than the broadcasting peer therefore creating a multiple delivery paths from source to other peers

Disadvantages of DHT with mesh overlay topology

  • complexity of the design of a Mesh overlay Topology
  • Consuming process ( tracking of all peers by each peer )

Advantages of circular DHT ( with no shortcuts )

  • less consuming process ( each peer tracks only two peers )

Disadvantages of Circular DHT ( with no short cuts )

  • The number of messages sent per query is minimized
  • 0(N) hopes are required to route message to a peer responsible for the key  

Distributed hash table (DHT) is a distributed system that provides a lookup service similar to a hash table. in the DHT key-value are stored in it

6 0
2 years ago
Write a client program that writes a struct with a privateFIFO name (call it FIFO_XXXX, where XXXX is the pid that you got from
ivann1987 [24]

Answer:

client code:

#include <stdio.h>

#include <fcntl.h>

#include <sys/stat.h>

#include <sys/types.h>

#include <unistd.h>

#include <stdlib.h>

#include <string.h>

int main (void)

{

 struct values

 {

   char privateFIFO[14];

   int intbuff;

 }input;

 int fda;  // common FIFO to read to write to server

 int fdb;      // Private FIFO to read from server

 int clientID;

 int retbuff;

 char temp[14];

 clientID = getpid();

 strcpy(input.privateFIFO, "FIFO_");

 sprintf(temp, "%d", clientID);

 strcat(input.privateFIFO, temp);

 printf("\nFIFO name is %s", input.privateFIFO);

 // Open common FIFO to write to server

 if((fda=open("FIFO_to_server", O_WRONLY))<0)

    printf("cant open fifo to write");

 write(fda, &input, sizeof(input));    // write the struct to the server

 close(fda);

 // Open private FIFO to read

 if((fdb=open(input.privateFIFO, O_RDONLY))<0)

    read(fdb, &retbuff, sizeof(retbuff));

 printf("\nAll done\n");

 close(fdb);

}

server code:

#include <stdio.h>

#include <errno.h>

#include <fcntl.h>

#include <sys/stat.h>

#include <sys/types.h>

#include <unistd.h>

#include <stdlib.h>

#include <string.h>

struct values

 {

   char privateFIFO[14];

   int intbuff;

 }input;

int main (void)

{

 int fda;  //common FIFO to read from client

 int fdb;  //private FIFO to write to client

 int retbuff;

 int output;

// create the common FIFO  

 if ((mkfifo("FIFO_to_server",0666)<0 && errno != EEXIST))

       {

       perror("cant create FIFO_to_server");

       exit(-1);

}

// open the common FIFO

 if((fda=open("FIFO_to_server", O_RDONLY))<0)

    printf("cant open fifo to write");

output = read(fda, &input, sizeof(input));

// create the private FIFO

 if ((mkfifo(input.privateFIFO, 0666)<0 && errno != EEXIST))

 {

   perror("cant create privateFIFO_to_server");

   exit(-1);

 }

 printf("Private FIFO received from the client and sent back from server is: %d", output);

 //open private FIFO to write to client

if((fdb=open(input.privateFIFO, O_WRONLY))<0)

   printf("cant open fifo to read");

 write(fdb, &retbuff, sizeof(retbuff));

 close(fda);

 unlink("FIFO_to_server");

 close(fdb);

 unlink(input.privateFIFO);

}

Explanation:

3 0
2 years ago
Other questions:
  • Consider a simple application level protocol built on top of udp that allows a client to retrieve a file from a remote server re
    15·2 answers
  • Computer hardware had been designed to run a single operating system and a single app, leaving computers vastly underutilized. o
    15·1 answer
  • The it department is reporting that a company web server is receiving an abnormally high number of web page requests from differ
    13·1 answer
  • In three to five sentences, describe how you can organize written information logically and sequentially
    8·1 answer
  • How do you think your ability to work might be affected if you don’t magnify a document so that text is at a size for you to rea
    9·1 answer
  • Susie works for an architectural firm and the partners have always drawn the plans for projects by hand. Though Susie learned ho
    11·1 answer
  • Nancy would like to configure an automatic response for all emails received while she is out of the office tomorrow, during busi
    13·2 answers
  • When you check to see how much RAM, or temporary storage you have available, you are checking your _____.
    7·1 answer
  • In an IPv4 datagram, the fragflag bit is 0, the value of HLEN is 5 (Its unit is word or 32-bits ), the value of total length is
    10·1 answer
  • I think you have been doing a great job but you haven’t been signing many people up for our new service feature I want you to se
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!