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
What is the approximate time and death in Sherlock Holmes
kati45 [8]

Answer: 8:58.5204 o'clock a.m

:)

3 0
2 years ago
Read 2 more answers
What can you achieve by selecting Insert in the Table menu?
BARSIC [14]
You can add row, table, columns or cells
4 0
3 years ago
Read 2 more answers
Q4. Write down the JavaScript statements to perform the following tasks.
goldenfox [79]

Answer:

Explanation:

In Javascript, you can accept an input value by using the prompt() function and saving the input into a variable. In the following lines of code, I have declared the three variables at the beginning and then prompted the user to enter a value for each and saved the values in the correct variables. In Javascript length is a keyword so I used len instead.

let base, height, len;

base = prompt("Enter Base value: ");

height = prompt("Enter Height value: ");

len = prompt("Enter Length value: ");

5 0
3 years ago
In contrast to data in a database, data in a data warehouse is described as subject oriented, which means that it _____.
jonny [76]

Answer:

focuses on a certain subject

Explanation:

it means that it focuses on that one subject and none others

Hope it helps c:

6 0
2 years ago
Anyone here codes? <br> C++, C#, Lua? Anything?
Travka [436]

Answer:

IxxyzjgzkgzjgKfzkg v

jvljcljxkhxkgg/gjhkggzkykzkgjzjgggggzjgcufxu

Explanation:

nk yxthzefhGghghrhgzxhhsdgchiixxu

7 0
3 years ago
Read 2 more answers
Other questions:
  • Which of these definitions BEST explains what plagiarism is:
    14·2 answers
  • Elise has just edited two photos of her cat and three different photos of her dog. She needs to save all five of these photos in
    5·2 answers
  • In this mode, your presentation will fill up the entire screen. Auto Default Standard Window
    6·2 answers
  • A collection of facts can be copyrighted, but only if the collection is ____ in a way that causes the resulting work to rise to
    14·1 answer
  • Cnt115-02* which of the following is a private ip address and can't be routed across the internet?
    12·1 answer
  • In what ways can you modify the location of the neutral point?
    11·1 answer
  • A database that is created and maintained using services such as Microsoft Azure or Amazon AWS is called a(n) _____ database.
    7·1 answer
  • How do I write this code in java? input "Enter Your Age to Order a Beer"
    11·1 answer
  • Call of duty vanguard, war zone , fornite, gta what’s your favorite
    11·1 answer
  • What two Python data structures are already thread-safe, because they provide automatic support for synchronizing multiple reade
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!