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]
1 year 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]1 year 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]1 year 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
To use the Web, each client computer requires a data link layer software package called a Web browser. True False
Luden [163]

Answer:

The answer is "False"

Explanation:

The data link layer is the protocol layer within a program, which controls data movement into a physical wireless connection. This layer is a second layer, that is also known as a collection of communications applications.

  • The server network, in which many clients request, and receive service from a centralized server.
  • This system provides an interface, that enables a user to request server services and view the server returns results, that's why it is wrong.
6 0
1 year ago
Dani is paraphrasing from a paragraph of an article for a post on her blog. Which of the following strategies is least likely to
koban [17]
I would say A. She reads the entire paragraph, then rewrites it in her own words, and then checks to make sure her version is not too similar to the text from the article.


All the other ones are a little too obvious.


Hope this helps you, baii <33

4 0
2 years ago
Read 2 more answers
You work for a shipping company and your manager receives orders from various customers everyday some existing ,some new .your m
Gennadij [26K]

Answer:

It's good to consider this as a dictionary, with key-value pair, or as a two-dimensional array.

And in the first case, the code will be as below:

day_i={'Bob':'100', 'Alice':'100','Celia':'110','Bob':'200'}

for k, v in day_i.items():

print(k, v)

Explanation:

The above code reads through each day, and each customer purchase amount in the form of Dictionary, and prints each customer name and purchase amount. And with little enhancement, we can create each day data, and print details of the day, as being asked by the user.

6 0
2 years ago
Write a static generic method PairUtil.minmax that computes the minimum and maximum elements of an array of type T and returns a
Gnesinka [82]

Answer:

Explanation:

The following code is written in Java. It is hard to fully create the code without the rest of the needed code including the T class and the Measurable interface. Regardless the following code can be implemented if you have that code available.

 public static T minmax(ArrayList<T> mylist) {

       T min = new T();

       T max = new T();

       for (int x = 0; x < mylist.size(); x++) {

           if (mylist.get(x) > max) {

               max = mylist.get(x);

           } else if (mylist.get(x) < min) {

               min = mylist.get(x);

           }

       }

       

       return (min, max);

   }

5 0
1 year ago
2. Sanjay thinks it's okay to plagiarize because he thinks his instructors won't find out. However, it's
Tatiana [17]
The correct answer is B
8 0
1 year ago
Other questions:
  • Match each function with its possible output.
    7·2 answers
  • If there are three classes, Shape, Circle and Square, what is the most likely relationship among them?
    15·1 answer
  • python A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun
    15·2 answers
  • The Pentium 4 Prescott processor, released in 2004, had a clock rate of 3.6 GHz and voltage of 1.25 V. Assume that, on average,
    8·1 answer
  • XYZ Corp.’s facilities in Nashua, New Hampshire, are two office buildings 400 feet apart, each with its own LAN. To connect the
    9·1 answer
  • You are the IT security administrator for a small corporate network. Samuel Garcia (sgarcia) has been away on vacation and has f
    9·1 answer
  • Your company wants to conduct an exploratory study to gain new insights into some product changes you are considering. Which typ
    15·1 answer
  • (1) Output a menu of automotive services and the corresponding cost of each service. (2 pts) Ex: Davy's auto shop services Oil c
    15·1 answer
  • Given the macro definition and global declarations shown in the image below, provide answers to the following questions:
    5·1 answer
  • Calvin is an aspiring graphic designer. He wants to achieve Adobe Certified Expert certification in software that will be helpfu
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!