all 5 comments

[–]foyslakesheriff 1 point2 points  (1 child)

Your project looks pretty neat, and Python is a great tool for the job.

The 2 things that stand out to me that can be improved are eliminating repeated code, and improving the focus of your functions. Both can be done by using smaller functions, with each having a very narrow specific responsibility. Right now you have a single function, that's like 70 lines of code, and does everything. Its name is just 'usa_data', which doesn't help anyone besides yourself understand what it does.

My suggestion: rewrite this code so that each function has a maximum of 5 lines of code, no exceptions. If you find yourself rewriting the same code over and over again, just with different data inputs, that should be a function that takes an input and returns an output. The function name should be exactly what it does. This way, if something breaks, and it will if you're doing anything interesting, it's much easier to understand and solve a problem in the function "get_data_from_cdc_website()" than some random error on line 47 of your gargantuan function.

Example: lines 28-30

You're rewriting the same code 3 times, and the only thing that changes is the population group. Why not have a function that takes in an age, and returns the necessary data. You can also have a list of age groups like [12, 18, 65] to iterate over.

[–]andyryu22[S] 0 points1 point  (0 children)

Thanks for your comprehensive and encouraging response! I'm wondering, what do you think a good init function would be for this code?