Rain¶
Save all functions into the same file named rain.py.
Write a function
rain1()that takes a list with the quantity of rain of the preceding years (liters per square meter, integer), and returns a tuple that contains the number of local minima (years in which it has rained less thant the year before and than the year after) and the number of local maxima (years in which it has rained more than the year before and than the year after). Examples:>>> rain1 ([300, 200, 400, 500, 450, 600, 550, 200, 400]) (3, 2) >>> rain1 ([300, 400, 450, 455, 450, 300, 240, 200, 199]) (0, 1) >>> rain1 ([300, 200, 400, 200, 450, 300, 550, 200, 400]) (4, 3)
Note
More tests are provided in the
rain1.txtfile.Write the function
rain2()that takes a list with the quantity of rain of the preceding years (liters per square meter integer), and returns a tuple with two lists. The first list contains the quantities corresponding to local minima (years in which it has rained less than the previous and than the following), and the second list, the quantities corresponding to local maxima (years in which It has rained more than the previous and than the following). The quantities of the lists obtained have to be in the same order than the ones of the initial list. Examples:>>> rain2 ([300, 200, 400, 500, 450, 600, 550, 200, 400]) ([200, 450, 200], [500, 600]) >>> rain2 ([300, 400, 450, 455, 450, 300, 240, 200, 199]) ([], [455]) >>> rain2 ([300, 200, 400, 200, 450, 300, 550, 200, 400]) ([200, 200, 300, 200], [400, 450, 550])
Note
More tests are provided in the
rain2.txtfile.
Solution
A solution of these functions is provided in the
rain.py file.