Explain me on how to go about this problem and check for all test cases 2 2.
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
2 2. FISHING TOWNS (4 MARKS) 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 is 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. 2 2. FISHING TOWNS (4 MARKS) 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 is 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)
The following is a Python program to solve the fishing towns problem Python def readfilefilename Rea... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
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...
-
Businesses use budgets to plan for the future. Thats what you will be doing for this assignment. Rather than budgeting for your current financial situation, I want you to put together a budget for...
-
Case Study: Quick Fix Dental Practice Technology requirements Application must be built using Visual Studio 2019 or Visual Studio 2017, professional or enterprise. The community edition is not...
-
Find the requested numbers(s) in Problems 1116. Classify the equation as true, false, or open; and if it is open tell whether it is a conditional, identity, or contradiction. a. Three times the sum...
-
The ledger of Montgomery Company at the end of the current year shows Accounts Receivable $78,000; Credit Sales $810,000; and Sales Returns and Allowances $40,000. Instructions (a) If Montgomery uses...
-
Briefly outline the advantages and disadvantages of the gold system.
-
Extend formula (8.2.5) to functions \(f\) defined on \(\mathbb{R}^{+} \times \mathbb{N}\) that are \(C^{1}\) with respect to the first variable, and prove that if \(\beta\) is a constant with...
-
Precision Painters, Inc., has five house painting jobs in one neighborhood. The houses differ in size, state of repair, and painting requirements, but each house must be prepped (cleaned, old paint...
-
Acqusitions are divided into three types namely i) Merger or Consolidation, ii) Acquisition of Stocks and iii) Acquisition of Assets. Explain briefly the characteristics of Acquisition of Assets.
-
Grove Audio is considering the introduction of a new model of wireless speakers with the following price and cost characteristics. Required a. What number must Grove Audio sell annually to break...
-
Assume analysts provide the following information. Assume short sales are allowed. Stock Expected Return Standard Deviation 1 12% 4% 2 10% 6% 3 9% 5% Correlation Coefficients Stock 1 Stock 2 Stock 3...
-
Revenue: $ 240,350 Utilities expense: $ 3,450 Interest received on bank account $ 4,670 Rent revenue: $20,000 Interest expense: $12,890 Costs of goods sold $60,500 Supplies expense: $2,670 Rent...
-
A conductor which is 30 cm long with a mass of 20 g is suspended horizontally in a magnetic field whose magnetic flux density is 0.12 T. What current is required in order that the magnetic force...
-
3. A technician is given 120 ml of a 50% (W/V) potassium chloride solution, and is told to add 300 ml of sterile water to it. What will the final (W/V) percentage concentration be of the solution? 4....
-
R Ltd. manufactures three products, A, B and C. The following information is given below. Sales Forecast Product Quantity Price Per Unit A 1000 Rs.100 B 2000 Rs.120 C 1500 Rs.140 Materials Used in...
-
3.1 A pipe with 200mm inner diameter should have a through flow of 10500 standard cubic meters per hour of CO2. ("standard-" or "norm-conditions" are 1.013 bar; 0C). How large are the a) mass flow b)...
-
Edwards Arthur Juda Sunglasses sell for about $154 per pair. Suppose the company incurs the following average costs per pair: (Click the icon to view the cost information.) Arthur Juda has enough...
-
Marc Company assembles products from a group of interconnecting parts. The company produces some of the parts and buys some from outside vendors. The vendor for Part X has just increased its price by...
-
Sophie is a single taxpayer. For the first payroll period in October 2012, she is paid wages of $3,250 monthly. Sophie claims three allowances on her Form W-4. a. Use the percentage method to...
-
Steve Drake sells a rental house on January 1, 2012, and receives $130,000 cash and a note for $55,000 at 10 percent interest. The purchaser also assumes the mortgage on the property of $45,000....
-
Fisafolia Corporation has gross income from operations of $220,000 and operating expenses of $160,000 for 2012. The corporation also has $20,000 in dividends from publicly traded domestic...
-
True or False: Engineers seldom have an opportunity to influence the recovery period for expenditures.
-
A lumber company purchases and installs a wood chipper for \(\$ 200,000\). The chipper is classified as MACRS 7-year property. Its useful life is 10 years. The estimated salvage value at the end of...
-
True or False: Straight-line depreciation is the most popular depreciation method used in financial reporting.
Study smarter with the SolutionInn App