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
The following SQL statement contains which type of subquery? SELECT title FROM books WHERE EXISTS (SELECT isbn FROM orderitems W
Rudiy27

Answer:

(a) Correlated.

Explanation:

Correlated subquery :These sub queries reference columns from outer table or uses values from outer query.These sub queries are processed atleast once for every row processed.So because of this reason correlated sub queries can be slow.Since the query in the question also uses value from the outer query so it is a correlated query.

4 0
3 years ago
FREE 10 POINTS THE EASIEST QUESTION EVER I AM NEW SO I DONT KNOW HOW TO MARK SOMEONE THE BRAINLEAST ????????????????????????????
umka2103 [35]

Usually you can just report the question as useless or just report in in general. But I myself have read some answers and they dont even pertain to the question, it confuses me alot

8 0
3 years ago
Read 2 more answers
What test must you pass to get you're operators licence
Alina [70]
Behind the wheel, the Florida driving test, turn about, shifting gears, parking, backing up, stop quickly, stop signs, signal & turns
5 0
3 years ago
What will happen if you type pseudocode in another language's programming environment and try to run the
wariber [46]

Answer:

You will get compile error

Explanation:

7 0
3 years ago
The National Archives is part of the federal government, which means that its content:
RUDIKE [14]

Answer:

belongs to everyone.

Explanation:

A National Archive can be defined as the collection of data (informations) and documents by the government of a particular country for record keeping purposes.

Basically, these documents comprises of information about important and historical events that have happened in the country or events generally related with the country.

Hence, the National Archives is part of the federal government, which means that its content belongs to everyone. This is simply because the federal government is a government of the people, for the people and by the people. Thus, the ownership of governmental institutions or agencies belongs to the general public i.e the citizens of the country.

4 0
3 years ago
Other questions:
  • It is not possible to convert a numbered list to a bulleted list in Word 2007. T or F
    13·1 answer
  • Which of the following is the BEST example of a strong password. Question 8 options: brian12kate5 chEwbAccAp!zza w3st! 123abccba
    10·2 answers
  • You can use ???? a to test tread wear on your tires
    14·2 answers
  • Suppose we provide a new implementation of the transport layer protocol tcp providing the same functionality using different alg
    14·1 answer
  • Rewriting notes into complete sentences is unnecessary if you want to include the notes in your study guide. Truth or false?
    15·2 answers
  • To drive defensively means taking proactive measures to avoid accident situations regardless of their potential causes.
    6·2 answers
  • What are potential problems with using nanorobots ?
    14·1 answer
  • Mika forgot to put in the function name in his function header for the code below. What would be the best function header?
    12·2 answers
  • Create a class to represent light bulbs
    7·1 answer
  • Which backup requires a small amount of space and is considered to have an involved restoration process?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!