Question: Write a program in python, in the file fish.py, that performs the following task. The program prompts the user to input a file name. If

Write a program in python, in the file 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 nonnegative 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 towns fishermen. For instance, the contents of the file coast_1.txt can be displayed as follows, 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 towns 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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!