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
#Electrical Engineering
GrogVix [38]

Answer:

yes

Explanation:

where's our question

5 0
3 years ago
1.the following code example would print the data type of x, what data type would that be?
natta225 [31]

Answer:

x = 5, the data type is integer( integer data type is for whole numbers)

2. The data type is string

3. The data type is float (float data type is for decimals)

Explanation:

6 0
2 years ago
Which of the following scan only works if operating system’s TCP/IP implementation is based on RFC 793?
Shkiper50 [21]

Answer:NULL Scan

Explanation:RFC 793(Request for comments) is a type of RFC command labeled with the number 793 which can operate with the TCP protocol.They are sort of document form which is from IETF( Internet Engineering Task Force ).

The null scan is scanning protocol used by legal as well as illegal hackers for working in the transfer control protocol architecture. It is used for the identification of the the ports and holes in TCP servers.they can also have the negative impact if used by the illegal hackers.

5 0
2 years ago
The TechWorld goes on a fast pace, what do you think would be the solution to the growing amount of data being collected by the
Nuetrik [128]

The solution to the growing amount of data in software applications to have fully sustainable usage for customers is;

  • Development of a sustainable model for the future now requires data storage that is engineered to be lower power requirements, lower cooling requirements, and lower waste production.

<h3>Sustainable data storage and usage</h3>

The objective of Sustainable Data Storage Initiative is to spread awareness of the solutions that can reduce the environmental impact of high waste producing data centers.

The environmental impact of data infrastructure is growing as data workloads increase. Hence, building a sustainable model for the future now requires data storage that is engineered to be lower power requirements, lower cooling requirements, and lower waste production.

Read more on Sustainable data storage and usage;

brainly.com/question/24882256

7 0
2 years ago
Assume there are 15 students registered for a history class. You will need to declare an array of the StudentType structure to c
andrezito [222]

Answer:

#include <iostream>

using namespace std;

struct StudentType{

   string studentName;

   int studentId;

}

int n;

char answer[20];

int main(){

   cout<< "Enter the size of the array: ";

   cin >> n;

   StudentType *student = new StudentType(n);

   for (int i = 0; i < n; i++){

       int name;

       int number;

       cin>> name;

       cin >> number;

       student[i].studentName = name;

       student[i].studentId = number;

   }

   for (int i = 0; i < 20; i++){

       cout<< "Enter answers: ";

       cin >> ans;

       answer[i] = ans;

   }

}

Explanation:

The C++ source code has three global variables namely, answer which is an array of character data type, StudentType which is a structure data type and the integer variable n. The main function declares and initializes the dynamic-spaced student array of the structure datatype with the n variable.

3 0
3 years ago
Other questions:
  • Which is the most efficient way to italicize a row of text in every worksheet in a workbook?
    8·1 answer
  • In the RGB model, which color is formed by combining the constituent colors?
    14·2 answers
  • Dustin runs a command at the command line trying to find out what kernel version the system is running. However, it doesn't give
    12·1 answer
  • Which of these is a method of selecting multiple items in Impress or PowerPoint? A. holding down the Ctrl key while clicking ite
    9·2 answers
  • Write a class "Dog" with a private int field called months and two public member functions setAge and GetStage. setAge takes as
    13·1 answer
  • 75+ (43-54)<br> -12<br> 12<br> 41
    12·2 answers
  • Mark is flying to Atlanta. The flight is completely full with 200 passengers. Mark notices he dropped his ticket while grabbing
    15·1 answer
  • Which TWO of these correctly describe a Trojan horse malware?
    11·2 answers
  • Meta is a penetration testing engineer assigned to pen test the security firm's network. So far, she cannot tunnel through the n
    12·1 answer
  • You want to be super private with your email. You'd like to be able to download your email to a single device, then remove it fr
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!