Question: Problem 4 b: Plotting the Prediction line Now, we ll use the predict _ need function to plot the best - fit line for US

Problem 4b: Plotting the Prediction line
Now, well use the predict_need function to plot the best-fit line for US consumption and a prediction out to 50 years from now.
For this problem (Problem 4b), add a line of code to call plot_linear_prediction(data, "USA") in your main code near the bottom of fishing.py (it must come after the call to parse_data). Running your program should then result in no errors and a new file named USA_need_prediction.pngbeing created in the same folder as your program.
The plot_linear_prediction(data, country_code) function is given to you in the utils.py starter file. This function takes the return value from parse_data as its first parameter and a country code (e.g.,USA) as its second parameter. It then calls the predict_need function you wrote in Problem 4a with the production need data for the given country code, and then plots the best-fit line and prediction. You do not need to write this function; its already been written for you. But it does rely on correct implementations for previous problems.
This function has no return value, but calling plot_linear_prediction(data, "USA") should produce a plot that resembles the following:
Problem 5: Total World-wide Production Need
Problem 5a:
So, now that weve done all that work, how much seafood will the entire world need to produce 50 years from now?
For this problem, write a function called total_production_need(data, years_to_predict) that returns a single number: how many metric tonnes will the world need to produce years_to_predict years from now?
This function should do the following:
Take as input the data returned from Problem 1s parse_data and a number of years in the future to predict.
For each country code, predict the production need for years_to_predictyears from now using Problem 4as predict_need function.
Get the last value in the predicted values.
For example, if you assign the return value from predict_need to prediction, you should be able to get the last value with prediction["values"][-1].
Sum up all of the predicted values.
Return the total.
Running your program with small.csv as the input file to parse_data, total_production_need should return a total production need of 13243690.762868665.(Your degree of precision may vary.)
Problem 5b: Running with the large file:
At this point, its time to run with the larger data file. Change the call to parse_data to use "large.csv" as its input. Then, at the very end of your program, add a print statement to print out the total you return from total_production_need. Your program should print the following:
Metric tonnes of seafood needed to be produced in 50 years: 245,637,243.224
Info
You can format very large numbers using Pythons f-string syntax. For example, if total =245637243.223947, doing print(f'{total_need:,.3f}) would print 245,637,243.224.

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 Programming Questions!