Write a program, stored in a file named fish.py, that performs the following task. The program...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a program, stored in a file named fish.py, that performs the following task. The program prompts the user to input a file name. If there is no file with that name in the working directory, then the program outputs an (arbitrary) error message and exits. The contents of the file consists of some number of lines, each line being a sequence of two strictly positive integers separated by at least one space, with possibly spaces before and after the first and second number, respectively, the first numbers listed from the first line to the last line forming a strictly increasing sequence. The first number represents the distance (say in kilometres) from a point on the coast to a fishing town further down the coast (so the towns are listed as if we were driving down the coast from some fixed point); the second number represents the quantity (say in kilos) of fish that has been caught during the early hours of the day by that town's fishermen. For instance, the contents of the file coast 1.txt can be displayed as 5 70 15 100 1200 20 which corresponds to the case where we have 3 towns, one situated 5 km south the point, a second one situated 15 km south the point, and a third one situated 1200 km south the point, with 70, 100 and 20 kilos of fish being caught by those town's fishermen, respectively. The aim is to maximise the quantity of fish available in all towns (the same in all towns) by possibly transporting fish from one town to another one, but unfortunately losing 1 kilo of fish per kilometre. For instance, if one decides to send 20 kilos of fish from the second town to the first one, then the second town ends up having 100-20=80 kilos of fish, whereas the first one ends up having 70+20-(15-5)=80 kilos of fish too. The program outputs that maximum quantity of fish that all towns can have by possibly transporting fish in an optimal way. Here is a possible interaction: $ cat coast 1.txt 5 70 15 100 1200 20 $ python3 fish.py Which data file do you want to use? coast 1.txt The maximum quantity of fish that each town can have 1s 20. $ cat coast 2.txt 20 300 40 400 340 700 360 600 $ python3 fish.py Which data file do you want to use? coast 2.txt The maximum quantity of fish that each town can have is 415. You can assume that the contents of any test file is as expected, you do not have to check that it is as expected. Write a program, stored in a file named fish.py, that performs the following task. The program prompts the user to input a file name. If there is no file with that name in the working directory, then the program outputs an (arbitrary) error message and exits. The contents of the file consists of some number of lines, each line being a sequence of two strictly positive integers separated by at least one space, with possibly spaces before and after the first and second number, respectively, the first numbers listed from the first line to the last line forming a strictly increasing sequence. The first number represents the distance (say in kilometres) from a point on the coast to a fishing town further down the coast (so the towns are listed as if we were driving down the coast from some fixed point); the second number represents the quantity (say in kilos) of fish that has been caught during the early hours of the day by that town's fishermen. For instance, the contents of the file coast 1.txt can be displayed as 5 70 15 100 1200 20 which corresponds to the case where we have 3 towns, one situated 5 km south the point, a second one situated 15 km south the point, and a third one situated 1200 km south the point, with 70, 100 and 20 kilos of fish being caught by those town's fishermen, respectively. The aim is to maximise the quantity of fish available in all towns (the same in all towns) by possibly transporting fish from one town to another one, but unfortunately losing 1 kilo of fish per kilometre. For instance, if one decides to send 20 kilos of fish from the second town to the first one, then the second town ends up having 100-20=80 kilos of fish, whereas the first one ends up having 70+20-(15-5)=80 kilos of fish too. The program outputs that maximum quantity of fish that all towns can have by possibly transporting fish in an optimal way. Here is a possible interaction: $ cat coast 1.txt 5 70 15 100 1200 20 $ python3 fish.py Which data file do you want to use? coast 1.txt The maximum quantity of fish that each town can have 1s 20. $ cat coast 2.txt 20 300 40 400 340 700 360 600 $ python3 fish.py Which data file do you want to use? coast 2.txt The maximum quantity of fish that each town can have is 415. You can assume that the contents of any test file is as expected, you do not have to check that it is as expected.
Expert Answer:
Answer rating: 100% (QA)
Heres the Python code for the fishpy program python import sys def loaddatafilenam... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Construct the current assets section of the balance sheet shown here from the following data: Yearly Credit Sales b. Inventory Turnover c. Current Liabilities d. Current Ratio e. c. Quick Ratio...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
There are two major producers of corncob pipes in the world. Suppose that the inverse demand function for corncob pipes is described by p = 120 - 4g where g is total industry output and suppose that...
-
In a study of the cognitive capacities of non-human primates, 19 monkeys of the same age are randomly divided into two groups of 10 and 9. The groups are trained by two different teaching methods to...
-
This question is to test your intuition. Read the following exercises (do not carry out the experiment). A. Open a phone book to any page in the white pages. Select 100 consecutive phone numbers and...
-
Explain the purpose of the Dow Jones Sustainability Indices.
-
Lynch Corporation has a wholly owned subsidiary in Mexico (Lynmex) with two distinct and unrelated lines of business. Lynmex's Small Appliance Division manufactures small household appliances such as...
-
6. 7. 8. The reaction of sulphur in alkaline medium is given below Sais) +aOH bs2 (aq) (aq) + CS0 (aq) + H2O (1) . (Integer answer) The values of 'a' is 4.5g of compound A (MW = 90) was used to make...
-
1. What is the correlation between Employee Engagement and Sales Revenue? 2. Consider the sign and the magnitude of the correlation. How would you describe the nature of the relationship between...
-
In what ways does cultural anthropology contribute to interdisciplinary dialogues and collaborations, drawing on insights from sociology, psychology, linguistics, and other fields to develop a...
-
Let f(x) = x+7x+12 and g(x) = x-9. A. Find (f*g)(x). B. Find (4)(x).
-
Explain why the cost of debt is typically different than the cost of equity. Give examples and explain your answers.
-
Several prominent commercial office buildings, which had been constructed by Granitex in the 1970's using aerated concrete at the client's request (for cheaper construction) also recently collapsed....
-
Oerstman, Inc., uses a standard costing system and develops its overhead rates from the current annual budget. The budget is based on an expected annual output of 125,000 units requiring 500,000...
-
Go to the link. https://www.schneier.com/crypto-gram/archives/2015/0515.html Take one of Bruce Schneier's cryptogram newsletters. And answer the following questions: 1. Link and date of newsletter....
-
The executor of Gina Purcells estate has recorded the following information: Assets discovered at death (at fair value): Cash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....
-
Explain from a technical viewpoint why it is important to distinguish a method, research, approach, and design. Next, briefly discuss how understanding each term individually in addition to how these...
-
Discuss the importance of validity and research design. Next, choose one type of validity (internal, external, construct, or statistical conclusion) and discuss its relevance to experimental, quasi...
-
Define a sampling strategy.
Study smarter with the SolutionInn App