Extra Credit Project:Functions
Due: Nov 28th at 11:59pm Note, this extra credit project
will overlap the final regular project since it is to help those who
struggled somewhere along the way catch up in credit.
I will assign Project 8 (the final regular project) on Nov 21
This project is extra credit and
will be used to replace a poor earlier project (it can only be used to
replace one of project 1-7). If you did poorly on an earlier project,
you can do this project and overwrite that grade. IF you did very well
on all of the earlier projects, there is no need to do this one.
Summary:
You will redo project 6, but this time with functions.
Details:
- First create your new project in pycharm with your name in the project
name
- Next add the openpyxl library the same way that we used the arcade
library in the past. You don't have to do anything with this library, my
code will use it
- Next get the file project6Files.zip and
save it into your project folder
- unzip the file, you should have three files now
- StateMedianIncome.xlsx (when grading I will use a file from a
different year)
- Erase the contents of main.py and copy the function from
Project6Loader directly into main.py
- create a main function and call it from the bottom of the file
- Do the same thing you did in project 6 (reminder below) except use
functions for everything. You should have a function for every one of
your menu conditions. be sure to pass the list of dictionaries as a
parameter. you can either report the results from this function, or
return the results and report them from the calling function
- You should have at least 7 functions including the main function and
the one I gave you to read the data from the excel file.
The original requirements for project 6, which you will now implement
using functions is below
Each dictionary is in the following format
|================================================+++++=========|
| "Name"
: <the state Name is a
string>
|
| "income2022"
: <median state income for 2022 as an int> |
|
"income2021" : <the state
median income for 2021 as int>|
|====================================================++++++=====|
Hint/Reminder from the PAL classes:
just like in the arcade package there are colors, in the colorama package
(which is in the python standard library) there are colors for printing to
the command line in color
colorama.Fore.<COLORNAME> is the general pattern for text colors. For example
print(colorama.Fore.BLUE +f"{income_data}")
will print whatever is in the variable income_data in blue
For the program functionality:
First ask the user what they want to do and then do one of the following
- Find wealthy states:
- ask the user to enter a yearly income amount.
- print all of the states and their median incomes from 2022 that had
more than that yearly income amount
- Find poor states
- ask the user to enter a yearly income amount.
- print all of the states and their median incomes from 2022 that had
less than that yearly income amount
- How is it changing?
- go through all of the data
- if the state has a higher median income in 2022 than the year
before, print its name in one color (maybe GREEN or CYAN or BLUE)
and print the change in income
- if the state has a lower median income in 2022 than in the year
before, print its name in another color (maybe RED or YELLOW) and
print the change in income
- Find Biggest Losers
- find all of the states that had more than $3000 dollar median income
loss from 2021 to 2022
- Print those state names and the change in median income with a
background color and message indicating that this is scary
- Find biggest Winners
- find all of the states that had more than $3000 dollar median income
gain from 2021 to 2022
- Print out state names and the change in median income with a
background color and message indicating that this is good.
Remember! I'll
use a different year (but the same dictionary keys) so the data will
be different, so you need to calculate the answers in the program
rather than just doing the work yourself and make your printer print
things out.
Of course put this into git and onto github sooner rather than later.
Additional requirements:
Your code must be commented. you don't have to comment every line, but you
need to explain to me what you are doing in the code.
Submission:
As with the previous project, to submit
the project to me, share it with me on github. My github id is jsantore.
You can see directions for doing this here.