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.

Answers

Answer 1

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()

Answer 2

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.


Related Questions

Write an HTML document which contains two text fields, a button, and a div. The first text field should be labeled “Temperature”, and the second should be labeled “Wind Speed”. The button should have the text “Wind Chill” written on it. Write two functions with these headers: function compute() function windChill(tempF, speed) The first function (compute) must be called from the onclick attribute of the button and must do the following: get a temperature from the first text field get a wind speed from the second text field call the second function (windChill) store the value returned by windChill in a variable output the value returned by windChill to the div for the user to see The second function (windChill) must take a temperature in Fahrenheit as a parameter take a wind speed in miles per hour as a parameter calculate the wind chill factor as a temperature in Fahrenheit return the wind chill factor in Fahrenheit In other words, the second function (windChill) must not gather any input from a user and must not output anything for a user to see. Instead it must calculate and return the result which makes this second function very reusable in other projects. The formula for computing the wind chill factor is f = 35.74 + 0.6215 t − 35.75 s0.16 + 0.4275 t s0.16 where f is the wind chill factor in Fahrenheit, t is the air temperature in Fahrenheit, and s is the wind speed in miles per hour at five feet above the ground.

Answers

Answer:

I created a jsfiddle for this: https://jsfiddle.net/tonb/o7uv4cdm/26/

Explanation:

see jsfiddle.

The usual html and body tags are omitted for simplicity. For your stand-alone page you'll have to put them in, as well as additional tags for your inline scripting.

An HTML document with two text fields, a button, and a div is presented to calculate the wind chill factor. JavaScript functions 'compute' and 'windChill' extract user inputs, perform computations, and display the result.

Below is an example of an HTML document that fulfills the requirements of containing two text fields labeled "Temperature" and "Wind Speed", a button titled "Wind Chill", a div to display the result, and the associated JavaScript functions needed to calculate wind chill.

<!DOCTYPE html>
<html>
<head>
<title>Wind Chill Calculator</title>
<script>
 function compute() {
   var tempF = document.getElementById('temperature').value;
   var speed = document.getElementById('windSpeed').value;
   var chill = windChill(tempF, speed);
   document.getElementById('result').innerText = chill;
 }

 function windChill(tempF, speed) {
   var t = parseFloat(tempF);
   var s = parseFloat(speed);
   if (t <= 50 && s > 3) {
     var f = 35.74 + 0.6215 * t - 35.75 * Math.pow(s, 0.16) + 0.4275 * t * Math.pow(s, 0.16);
     return f.toFixed(2);
   } else {
     return "N/A";
   }
 }
</script>
</head>
<body>
<label>Temperature (℉): <input type="text" id="temperature"></label>
<br>
<label>Wind Speed (mph): <input type="text" id="windSpeed"></label>
<br>
<button onclick="compute()">Wind Chill</button>
<div id="result"></div>
</body>
</html>

The compute function is responsible for retrieving values from the input fields, calling the windChill function with those values, and then displaying the result. The windChill function takes the temperature and wind speed, calculates the wind chill factor using the provided formula, and then returns it for display.

What is the role of the constructor for an object?

Answers

Answer:

A constructor is responsible for preparing the object for action.

What is the purpose of the transport layer in managing the transportation of data in end-to-end communication? Explain how it should be used in the troubleshooting process.

Answers

The transport layer is used to establish this connection whenever an IP communication session needs to start or end.

What transport layer in managing the transportation?

The transport layer facilitates communication between application processes running on various hosts within a layered architecture of protocols and other network elements.

In a nutshell, the transport layer gathers message fragments from applications and transmits them into the network.

A complete end-to-end solution for dependable communications is offered by the transport layer.

Transport layer shows you the best path, with the most security, to your destination. This is where the data transportation happens.

Therefore, TCP/IP relies on the transport layer to effectively control communication between two hosts.

Learn more about transport layer here:

https://brainly.com/question/4727073

#SPJ2

Identify an advantage of centralized processing

Answers

Answer:

In a centralized organization structure, the centralized authority may have a better perspective on the big picture of the organization and how the subunits of the organization fit together and this may make centralized authority optimal.

Please mark brainliest, hope this helped :)

The ____ component of an information system consists of raw facts and by itself

Answers

Answer: Data

Explanation: Data can be quantitative or qualitative. Information is data that has been given context. Knowledge is information that has been aggregated and analyzed and can be used for making decisions.

Final answer:

The 'data' component of an information system is a collection of raw facts and observations. Once data is put into context, it becomes 'information,' which refers to processed and valuable knowledge from the raw data. Computing technologies are instrumental in transforming data into information and support tasks like data storage and analysis.

Explanation:

The data component of an information system consists of raw facts and by itself represents measurements or observations of phenomena. Data is the foundational element from which information is produced in an information system, such as a database management system. When data is contextualized, interpreted, and analyzed, it then becomes information, which is valuable knowledge used to answer questions and make decisions. In the context of a Geographic Information System (GIS), for example, data might include the measurements of mountain peaks or the number of people using public transportation, while information is what we derive from analyzing these measurements to understand trends or patterns.

Information technology, such as computers, facilitates the transformation of data into information by automating repetitive tasks, storing data efficiently, and offering tools for complex analyses. This technology is essential in collecting the immense quantities of data from sources like satellites and smartphones, enabling us to turn these raw facts into actionable insights.

Explain what LIFO and FIFO mean, and how they are used in Abstract data types?

Answers

Answer:

LIFO stands for Last In First Out. This procedure is used in the Stacks in data structures.Stacks are the data types in which the data is stored called Stack.

Explanation:

What are the key goal, performance, and risk indicators?

Answers

Answer:

KRIs are a way to quantify and monitor the biggest risks an organisation (or activity) is exposed to. By measuring the risks and their potential impact on business performance, organisations are able to create early warning systems that allow them to monitor, manage and mitigate key risks.

Effective KRIs help to:

Identify the biggest risks. Quantify those risks and their impact. Put risks into perspective by providing comparisons and benchmarks. Enable regular risk reporting and risk monitoring. Alert key people in advance of risks unfolding. Help people to manage and mitigate risks.

While KPIs help organisations understand how well they are doing in relation to their strategic plans, KRIs help them understand the risks involved and the likelihood of not delivering good outcomes in the future.

describe 2 health risks posed by computers

Answers

Answer:

Bad posture and eye strain are two health risks posed by computers. Hand and wrist problems are other health risks posed by computers.

What is multiprogramming?

Answers

Answer:

Multiprogramming is a rudimentary form of parallel processing in which several programs are run at the same time on a uniprocessor. Since there is only one processor, there can be no true simultaneous execution of different programs. Instead, the operating system executes part of one program, then part of another, and so on. To the user it appears that all programs are executing at the same time.

Explanation:

Final answer:

Multiprogramming refers to a computer system running multiple programs at the same time by allocating system resources to multiple processes, maximizing CPU usage. It should not be confused with multitasking, which often relates to individuals performing several tasks simultaneously, a practice that can decrease efficiency if the tasks are complex.

Explanation:

Multiprogramming is a concept in computer science where a computer system runs multiple programs at the same time. This is achieved by having the operating system allocate resources to multiple processes in such a way that it maximizes CPU usage by switching between them. Each program is given a slice of the processor's time and then it is swapped out for another program, ensuring that the right amount of attention is given to each program without any one of them monopolizing the processor. This switching happens so quickly that it gives the illusion of programs running simultaneously.

While multiprogramming increases the efficiency of system resource utilization, it requires careful management of memory and CPU allocation to ensure that all programs get the necessary resources to operate effectively. It is different from multitasking, which generally refers to an individual performing several tasks at once, and often with variable success depending on the complexity of the tasks involved.

Moreover, in an agency or business context, multitasking can refer to an employee being given various roles or tasks and the need for incentives to guide not only the total effort of the employee but also the distribution of their time and effort across these tasks. This differentiation is important in designing incentives that are effective without negatively impacting the performance of the individual tasks.

How do apps and devices call the OS?

Answers

OS will provide interface for an application to use, so an OS’s services as functions can be called from application programs (operating system acts as an intermediary between programs and the computer hardware)

_____ uses an iterative process that repeats the design, expansion, and testing steps as needed, based on feedback from users.

Answers

Hello There!  

Rapid application development (RAD)

uses an iterative process that repeats the design, expansion, and testing steps as needed, based on feedback from users.

Narrowband technologies deliver data at up to a) 64 Kbps b) 128 Kbps c) 256 Kbps d) None of the above

Answers

Answer:64kbps

Explanation:

how might computers have a negative effect on the enviroment

Answers

Answer:

The negative effects of computer use on the environment There are several effects computer use has on the environment. Not only does it affect the environment but also human health.

Explanation:

First of all, sometimes people (especially in businesses) print unnecessary large amounts of files, emails or things from the internet which wastes paper and harms trees. People who use computers never really turn off the device which wastes electricity that could have been saved and reduce the amount of burning of fossil fuel.

Secondly, computers are made of heavy metals and dangerous chemicals. Heavy metals including Lead, Mercury,Beryllium,Cadmimum, PCV e.t.c

These metals and chemicals contribute to global warming because from these discarded computers it causes water contamination and air pollution.

Computers have negative effects on the environment, as heavy metals like lead and toxic chemicals found in computers contaminate groundwater and the environment.

What are the effects of computer?

The harm that using computers causes to the environment The use of computers has a variety of negative environmental effects. It has an impact on both the environment and human health.

First off, printing excessive amounts of files, emails, or other content from the internet can sometimes be done by people (especially in businesses), which wastes paper and puts a strain on the environment. People who use computers rarely turn them off, wasting energy that could have been saved and lowering the amount of fossil fuel burned.

Therefore, due to the contamination of groundwater and the environment by toxic chemicals and heavy metals like lead found in computers, computers have a negative impact on the environment.

To learn more about computers, refer to the below link:

https://brainly.com/question/23137168

#SPJ2

Hub is used in Twisted pair Ethernet. True/False

Answers

True or false, Answer:True

____________ is the practice of hiding data and keeping it away from unauthorized users.

A. Cryptography

B. Ciphertext

C. Cybersecurity

D. Encryption

Answers

Answer:

D.

Explanation:

A. Cryptography, D is not the correct answer because it is a process not a practice.

An icon can be specified for a tab using the _____ method.

addTab
setIcon
setImage
tabIcon

Answers

Answer:

setIcon

Explanation:

In design support library the components like nav bar, floating action button, snackbar, tabs, labels and animation frameworks we use icons and different other designs to look theme appealing.

So the icon can be specified for a tab using the setIcon method.

tabLayout.getTabAt(0).setIcon(tabIcons[0]);

tabLayout.getTabAt(1).setIcon(tabIcons[1]);

Describe the components of the Ethernet frame in detail?

Answers

Starts with an Ethernet header, which contains destination and source MAC addresses as its first two fields

A _____ is used by a host to forward IP packets that have destination addresses outside of the local subnet.

Answers

Ip packets are forwarded using the default gateway that is being used by the host.

Explanation:

Ip packets are forwarded using the default gateway that is being used by the host, where it has placed their destination addresses on the outside of the local subnet. The default router is another representation of the default gateway. It is also known as the default router. The computer sends the packets to the default router when it wishes to send to any other subnet. In-network this device is being a point of access to the other networks.

You need a disk system that provides the best performance for a new application that frequently reads and writes data to the disk. You aren't concerned about disk fault tolerance because the data will be backed up each day; performance is the main concern. What type of volume arrangement should you use?

Answers

a. Spanned volume

b. RAID 1 volume

c. RAID 0 volumed

RAID 5 volume

It is important to remember that in a supply? chain, the only source of revenue is the? _______.manufacturer/customer/raw material supplier/distributor/retailer

Answers

probably the retailer

What are the advantages of using variables in a data type?

Answers

Answer:

A variable is a name associated with a data value; we say that the variable "stores" or "contains" the value. Variables allow us to store and manipulate data in our programs.

Discuss anomaly detection.

Answers

Hello There!

Anomaly Detection is used to identify unusual patterns that is not usually expected behavior.

On social media, it's finding profiles that behave oddly or act differently than everyone else. This is called an outlier

Which of the following statements is false?

A Path object represents the location of a file or directory.

Path objects open files and provide file processing capabilities.

The Paths class is used to get a Path object representing a file or directory location.

The Path method isAbsolute returns false if the Path is relative.

Answers

Answer:

Path objects open files and provide file-processing capabilities. Actually, Path objects do not open files nor do they provide any file-processing capabilities. They specify only the location of a file or directory.

Describe the Wal-Mart?

Answers

Answer:

The largest discount retailer in the world. The company started out as a small chain of stores in rural towns. The store chain was founded by Samuel Walton in 1962 and currently is one of the largest employers in the United States. The store has been criticized for running smaller "mom and pop" stores out of business with its extremely low prices. Some of the stores are considered Super Wal-Marts and they typically provide a grocery store and automotive repair shop for customers.

What is the current competitive position of Nintendo?

Answers

Answer:

Sony and Microsoft

Explanation:

Answer:

Sony and Microsoft.

Explanation:

Xbox is nintendo's biggest competitor in the gaming industry with PS4 hitting Nintendo hard.

Hope I helped!

The __ is the section of a cpu core that performs arthimetic involving integers and logical operations

Answers

The Arithmetic/Logic Unit

Which of the following regarding the Ames test is true? a. It is used to identify newly formed auxotrophic mutants. b. It is used to identify mutants with restored biosynthetic activity. c. It is used to identify spontaneous mutants. d. It is used to identify mutants lacking photoreactivation activity.

Answers

Answer:

A

Explanation:

The answer to this question is option b. The Ames test is used to identify mutants with restored biosynthetic activity.

The Ames test makes use of bacteria to ascertain if mutation can occur in the DNA of an organism using a certain chemical compound.

It can also be used to test if a drug possesses  mutagenic properties. The bacteria strain that is used is the Salmonella typhimurium. The mutation of this bacteria occurs in histidine.

Read more at https://brainly.com/question/13052478?referrer=searchResults

Higher-speed Ethernet technologies use an electronic device known as a Hub rather than a switch True/False

Answers

this should be false

Write a program that asks for 'name' from the user and then asks for a number and stores the two in a dictionary (called 'the_dict') as key-value pair. The program then asks if the user wants to enter more data (More data (y/n)? ) and depending on user choice, either asks for another name-number pair or exits and stores the dictionary key, values in a list of tuples and prints the list. Note: Ignore the case where the name is already in the dictionary. Example: Name: pranshu Number: 517-244-2426 More data (y/n)? y Name: rich Number: 517-842-5425 More data (y/n)? y Name: alireza Number: 517-432-5224 More data (y/n)? n [('alireza', '517-432-5224'), ('pranshu', '517-244-2426'), ('rich', '517-842-5425')]

Answers

Answer:

Okay. I am doing it with Python. Hope it'll help you to understand the concept.

Code:

the_dict={}   #Creating a dictonary

def dat():    # Creating a function named dat()

   

   name = input('Your Name: ')   # Data from user

   ph = input('Phone Number: ')

   for i in range(1):  #Creating loop

       the_dict[name]=ph   # Placing the value in dictonary

   more = input('More Data (y/n): ')   # Asking for More data

   if more == 'y':   # if more is y then run the function dat()

       dat()   # calling dat()

   elif more == 'n':   # if more is n then print the dictonary named 'the_dict'

       print(the_dict)

   else:

       print('Wrong Input')  # if wrong input print the message and run dat() again

       dat()

dat()  # calling the function

   

Result:

Your Name: PyMan

Phone Number: 9814579063

More Data (y/n): y

Your Name: PyMman2

Phone Number: 451513262026

More Data (y/n): y

Your Name: C#Man

Phone Number: 7798822222

More Data (y/n): n

{'PyMan': '9814579063', 'PyMman2': '451513262026', 'C#Man': '7798822222'}

Below is the required Python code.

Python

Program:

#Creating a dictionary

the_dict={}  

#Creating a function

def dat():    

   

  #Input data

  name = input('Your Name: ')  

  ph = input('Phone Number: ')

  #Creating a loop

  for i in range(1):  

      #Placing the value in dictionary

      the_dict[name]=ph  

  #Asking the user for more data  

  more = input('More Data (y/n): ')  

  #Run the function, of more is "y"

  if more == 'y':

     

      #Calling the function dat()

      dat()  

  #Print the dictionary named "the_dict", if more is "n"

  elif more == 'n':  

      print(the_dict)

  else:

      #Print the message and run the function, if wrong

      print('Wrong Input')  

      dat()

#Function calling

dat()  

Program explanation:

Creating a dictionary and function.Input data.Creating a loop.Placing the value in dictionary.Asking the user for more data.Run the function, of more is "y".Calling the function.Print the dictionary named "the_dict", if more is "n".Print the message and run the function, if wrong  

Output:

Find below the attachment of program output.

Find out more information about Python here:

https://brainly.com/question/26497128

Describe an application or a situation in which it is not convenient to use a linked list to store the data of the application

Answers

Answer:

A linked list is a linear data structure. In which elements are not stored at contiguous memory location. The element in a linked list using pointers.

Explanation:

"It is not convenient in case of more memory use than array because pointer storage, second it is incontiguous so it increased time period required to access individual element within the list, specially CPU cache. Third problem is that when we reverse traversing linked list."

Final answer:

Linked lists are not convenient for frequent insertions or deletions of elements, such as in a messaging application. Linked lists also do not support random access to elements based on an index.

Explanation:

An application or situation where it is not convenient to use a linked list to store data is when frequent insertions or deletions of elements are required. Linked lists have a constant time complexity for accessing elements based on their position in the list, but the time complexity for inserting or deleting elements is linear. If an application requires frequent modifications to data, using a dynamic array or a binary search tree may be more efficient.

For example, in a messaging application where new messages are constantly added and old messages are removed, using a linked list may result in slower operations to insert or delete messages compared to using a dynamic array or a binary search tree.

Another situation where a linked list may not be convenient is when random access to elements is needed. Linked lists do not support direct access to elements based on an index. If an application needs to access elements by their position in the list efficiently, using an array or an indexed data structure would be a better choice.

Other Questions
I'm just done with math... as long as you explain it I'll mark your brainiest. Healthcare costs are becoming an issue for many Americans. In just two years, the average family has seen an increase of 3 percent in insurance costs. The increase rises to 25 percent when you include families who buy insurance on an exchange. At this rate, health care will soon be completely unaffordable for most Americans. Therefore, lowering the cost of health insurance must be a priority for lawmakers.Which statement best explains why the argument is logical?A.)The argument incorporates empirical and anecdotal evidence. B.)The argument includes a strong counterclaim and a fair rebuttal. C.)The argument contains relevant reasons supported with facts and data.D.)The argument includes a personal experience as an emotional appeal. What is the number of protons in the nucleus of an element called? why would two different species have similar features or behaviors?A.similar DNA B.similar mutationsC.similar environmental pressures Find the area of a square with a diagonal of 8 cm. Which pronoun has an unclear antecedent in the following sentences? The sixth-grade students liked volunteering their time to read to the elderly people in the hospital. It made them happy. A. Their B. It C. Them D. No unclear antecedents Jessica is deciding on her schedule for next semester. She must take each of the following classes: English 101, Spanish 102, Biology 102, and College Algebra. If there are 15 sections of English 101, 9 sections of Spanish 102, 11 sections of Biology 102, and 15 sections of College Algebra, how many different possible schedules are there for Jessica to choose from? Assume there are no time conflicts between the different classes. Which kind of aquatic ecosystem does the photograph most likely show?A. MarshB. SwampC. LakeD. River Which effect does the repetition of to have in the paragraphs that begin to those, forexample?It creates a comical, singsong effect that brings out the humor in histhemes.CB.It creates a monotonous, repetitive effect that undermines his themes.Cc.It creates a rhythm and expanding scope that reinforce his themes.ResetNext Find the area and perimeter of the following figure, please help a.s.a.p Question 15 of 252 PointsRead the following excerpt from a speech:It has been suggested that all automobiles be convertedto electric power by the year 2020. _ there simply isn'tthe infrastructure in place to accommodate such achange.Which word or phrase best connects the ideas in these sentences?OA. NowadaysOB. ThereforeOc. In contrastOD. Unfortunately which RNA is found inside the nucleus? Chicken pox is a virus that causes an itchy rash but typically does not have any major or lasting effects on an infected person. Before 1995, chicken pox parties were popular. In a chicken pox party, healthy children were brought around children who were sick with chicken pox so that they would be exposed to the virus and their immune system would learn to fight it. A vaccine for chicken pox was developed in 1995, and chicken pox parties are now rare. What best describes how vaccines have advanced science? Vaccines are more effective on ethnicities that are highly susceptible to a disease. Vaccines can determine which genes can cause disease. Vaccines can minimize lifestyle choices that allow for greater exposure to a disease. Vaccines allow for building immunity without harmful exposure because not all viruses are safe to be exposed to How does this scene most contribute to the plot? Will give brainliestSum of Arithmetic Series (Sigma Notation)Find the numerical answer to the summation given below.(Image Shown Below) The idea that states could ignore federal law was calledMark this and retumSave and ExitNextSubmit The line that separated Communist countries from free countries in Europe was called "the Iron Curtain." The process by which formed elements are produced is called ______.A. hemocytoblast B. hemopoiesis C. homeostasis D. erythropoiesis Helen is 72 years old and is a retired school teacher on a fixed income. She would like to buy a new computer so that she can communicate via email, follow friends and family on social media, and occasionally access recipes and gardening tips from the Web. An important thing to consider is that Helen has arthritis in her hands, making it difficult for her to work with small buttons and gadgets. So, of the following options, her best choice is probably a(n) ________.a. e-bookb. nettopc. desktopd. smartphone A helical gear has 30 teeth and a pitch diameter of 280 mm. Gear module is 8 and pressure angle normal to tooth is 20. The force normal to the tooth surface is 4500 N. Determine the kW transmitted at 620 rpm.