
In this second guided project, You will develop code for an application that allows users to see a summary of their annual expenses and savings. Applications such as Quicken and EveryDollar provide advanced functionality for users to track and visualize their expenses. In this project, you’ll implement a similar, though greatly simplified version of these types of applications. Having a clear understanding of where your money goes, how much you are saving, and how much you invest is important to financial success. As a famous author once wrote:
Annual income twenty pounds, annual expenditure nineteen six, result happiness.
Annual income twenty pounds, annual expenditure twenty pound ought and six, result misery.
–Charles Dickens
This program will work by accepting 5 input values regarding how much the user earns and spends. After printing out a welcome message, the program will request all 5 of these inputs. Below is an example of these input requests, with values provided:
--------------------------------
----- FINANCIAL VISUALIZER -----
--------------------------------
Annual Salary:
50000
Monthly Housing:
1000
Monthly Bills:
400
Weekly Food:
200
Annual Travel:
2500
These 5 values will be used to generate a visualization of the financial situation that looks like so:
----------------------------------------------------------
housing | $ 12,000.00 | 24.0% | ########################
bills | $ 4,800.00 | 9.6% | #########
food | $ 10,400.00 | 20.8% | ####################
travel | $ 2,500.00 | 5.0% | #####
tax | $ 10,000.00 | 20.0% | ####################
extra | $ 10,300.00 | 20.6% | ####################
----------------------------------------------------------
The result will always be a 6-row, 4-column grid that neatly shows that amounts and percentages of income and expenses.
Each row represents an expense (or other category) where money goes on an annual level.
The first column provides the name of the category.
The second column shows the amount of money that goes to this category in dollars per year.
The third columns shows the amount of money as a percentage of yearly income (salary).
The last column is a horizontal bar that correlates with the percentage of income.
The number of # characters in this column should be the same as the percentage of income (rounded down).
As with most programs, it’s not typically a good idea to attempt solving a large problem all in one go. Instead, we should attempt to break it up into smaller, more manageable chunks and attack each individually until the whole is complete. Taking this to heart, this guided project will be divided up into several stages for you to complete separately:
input().if statements and the isnumeric() function to ensure all of the collected inputs are valid.
Note that I have not discussed the isnumeric() function in the lesson thus far!
This is a method that can be called on a string to determine if it contains only numerical digits or not.
For more information see the documentation here.if-statements.The first step requires fetching the 5 inputs.
You should write the code to get all of these input values, using the input prompt messages as shown in the example earlier in this project.
Ensure that you end each input prompt with a newline.
Each value should be stored into variables named salary, housing, bills, food, and travel respectively.
You should also print out the “FINANCIAL VISUALIZER” welcome banner as shown in the example.
If a program expects a particular type of input value, it’s important to check and determine if what was provided by the user is the right type.
In this case, the program expects to get only numeric data from the user.
The data it gets could have decimals, as it’s possible a user spends $47.50 each week on groceries.
Thus, we need to validate and check that all 5 of these input values can be safely converted to a floating-point number before doing the conversion.
If a user types in something that isn’t a number when prompted for food expenses (such as 'too much') and then the program converts this to a float, and error will occur.
We want to avoid such scenarios.
Instead the program must check if the salary, housing, bills, food, and travel strings can be safely converted to a float.
This means the string must only include digits '0' - '9' and a period '.'.
If the program detects any of these are not so, it should print Invalid input, please try again. exactly one time.
If they are all valid, print All inputs confirmed valid. exactly once.
Write one or more if-statements in the following code editor to check this.
Assume that the 5 variables have already been created.
The tax amount needs to be calculated based on the salary. Real tax codes are quite complex (at least in the U.S.) so a simplified system will be described. In the simplified system, there will be four tax brackets, each of which requires a different percentage of the users income. The bracket percentages to not incrementally accumulate. Rather, whatever tax bracket a user falls into, that percentage of their full salary is what they pay. The brackets are as follows:
$0 - $10,000 income pays 5% tax.$10,001 - $40,000 pays 10% tax.$40,001 - $80,000 pays 15% tax.$80,001+ pays 20% tax.Write the code to determine and print out the tax value.
You should assume that the salary variable has already been created and converted to a float.
The program should print out the float value of the taxes, rounded to 2 decimal places using the round() function.
For example, if salary was the value 50009 then the code you write should print out the number 7501.35.
Write your code for this using if-statements below:
In this step, two main things need to be calculated.
First, the input values need to be converted to annual amounts instead of weekly and monthly, where necessary.
Second, the percentage must be computed for each.
In order to convert values to annual, the monthly values must be multiplied by 12, and the weekly value (food) must be multiplied by 52.
To calculate percentages, each annual value must be divided by the total income (salary), multiplied by 100, and rounded to two decimal places.
After performing these calculations, print out the values and check if they look correct.
There won’t be built-in test cases for this step, as getting all of these numbers printing and formatted to match the test exactly can be a pain.
However, you should check your work to see if the results are correct based on the inputs.
For this step, you may want to use the string format() method.
You can find more information about this function in the Python documentation.
The final step is to print the bar chart. Getting to this final point requires all of the prerequisite tasks to be completed. In order to produce the bar chart, you must have already computed the taxes, percentages, and annual dollar amounts. And of course before these, you must get and validate all input values. In this final step, you must get the bar chart printing out. In addition to the one at the beginning of the assignment, here is another example of what the output plot should look like:
--------------------------------
----- FINANCIAL VISUALIZER -----
--------------------------------
Annual Salary:
Monthly Housing:
Monthly Bills:
Weekly Food:
Annual Travel:
All inputs confirmed valid.
-----------------------------------------------------------------------
housing | $ 24,000.00 | 24.0% | ########################
bills | $ 8,400.00 | 8.4% | ########
food | $ 5,200.00 | 5.2% | #####
travel | $ 5,000.00 | 5.0% | #####
tax | $ 20,000.00 | 20.0% | ####################
extra | $ 37,400.00 | 37.4% | #####################################
-----------------------------------------------------------------------
In this last step, you should write the code to get the plot printing out as shown above. You don’t need to get it identical, but you should get as close as you can. Variables for the annual and percentage amounts will be pre-populated for you, so you can focus on just the last step of printing and formatting.
Congratulations on completing this project. You can download the solution code via the link below to see the full program, with all of the components of the 5 steps working together (with a few modifications).