-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject-3.qmd
202 lines (142 loc) · 8.28 KB
/
project-3.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
---
title: "Programming Project 3"
---
```{r}
#| echo: false
#| message: false
#| warning: false
library(tidyverse)
library(readxl)
assignments <- read_excel("assessment_schedule.xlsx") %>%
mutate(formatted_date = format(due_date, "%A, %B %d, %Y"))
```
Programming Projects are to be submitted to [gradescope](https://www.gradescope.com/courses/934148)
**Due date: `r assignments %>% filter(assessment == "Programming Project 3") %>% pull(formatted_date)` at 9pm**
This programming project is an adaptation of Ben Dicken's Where's the Money Programming Assignment.
Do not import any modules for this assignment. Do not use built-in functions like max() (you have to
write your own). You can use the built-in functions we covered in class: `print()`, `round()`, `input()`, `len()`, `int()`, `float()`, `str()` in addition to `format()`.
# Where's the Money
Budgeting and money management is very important both at the individual level, and for corporations and government. 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*
In this assignment, you will be writing a program that helps a user visualize and understand how much money they spend of various categories of expenditures. Perhaps you will even find this program useful for your personal finances! You should name your program `wheres_the_money.py`.
# Overview of the program
This program takes a number of various arguments about how much someone makes, and how much they spend. The program will accept 5 argument values:
* Annual salary
* Monthly mortgage or rent
* Monthly bills
* Weekly grocery/food expenses
* Annual travel
These 5 values will be used to generate a visualization of the financial situation that looks like so:
<pre>
------------------------------------------------------------------
See the financial breakdown below, based on a salary of $50000
------------------------------------------------------------------
| mortgage/rent | $ 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% | ####################
------------------------------------------------------------------
</pre>
As you can see, the result is essentially a 6-row, 4-column grid that neatly shows that amounts and percentages of income go where.
Each row represents an expense (or other category) where money goes to on a yearly basis. The first columns provides the name of the category. The second column shows the amount of money that goes to this category in dollars. The third columns shows the amount of money as a percentage of yearly income. The last column is a horizontal bard 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).
# Calculating the values
The output provided above shows the kind of output this program should produce. Let’s talk a bit about how to compute these values.
The basis for all of the percentages is the annual income argument. All of the percentages are calculated based on this. The next two arguments, rent and bills, are monthly expense values. In order to get the total spend on these categories annually, these numbers must be multiplied by the number of months in a year. Then, you can use this result to calculate the percentage. The fourth value is a weekly expense, so this must instead be multiplied by the number of weeks in a year. The fifth argument is already an annual value, so you don’t need to multiple by number of weeks or months.
You need to write a `calculate_tax` function to calculate taxes. The tax percentage is dependent upon the amount of money a person make annually. The tax brackets are as follows:
* [$0, $15k] annually: 10% tax
* ($15k, $75k] annually: 20% tax
* ($75k, $200k] annually: 25% tax
* over $200k annually: 30% tax
You should use one or more if / elif / else statements in the code to determine which tax percentage to use. You can store the tax percentage as an integer variable, with one of the following values: 10, 20, 25, or 30. You can compute the amount of the salary goes to taxes as a particular percentage with this formula:
```{python}
#| eval: false
#| echo: true
annual_salary * ( tax_percentage / 100.0)
```
Here are some tests to verify you are calculating the taxes correctly:
```{python}
#| eval: false
#| echo: true
assert calculate_tax(40000) == 8000
assert calculate_tax(10000) == 1000
assert calculate_tax(20000) == 4000
```
After calculating all of these values programmatically, you should generate the output table. Print the table in the `wheres_the_money` function.
Finally, after printing the table, two warnings are optional to print (overspending & tax limit).
Overspending - what happens if the expenditures and taxes are more than the annual salary? This should be represented by negative values in the extra row. You should also print a warning after the chart. Below is an example of a financial situation in which the user spends more than they earn, resulting in a deficit in the extra row.
```{python}
#| eval: false
#| echo: true
# arguments: salary, mortgage/rent, bills, food, travel
wheres_the_money(40000, 2000, 300, 150, 4000)
```
<pre>
------------------------------------------------------------------------------------------------------
See the financial breakdown below, based on a salary of $40000
------------------------------------------------------------------------------------------------------
| mortgage/rent | $ 24,000.00 | 60.0% | ############################################################
| bills | $ 3,600.00 | 9.0% | #########
| food | $ 7,800.00 | 19.5% | ###################
| travel | $ 4,000.00 | 10.0% | ##########
| tax | $ 8,000.00 | 20.0% | ####################
| extra | $ -7,400.00 | -18.5% |
------------------------------------------------------------------------------------------------------
>>> WARNING: DEFICIT <<<
</pre>
Tax limit - there is also a tax limit of `$75,000`. The tax should be capped at this value, and if the limit is reached, a message indicating this should be printed out after the chart. The message should say:
<pre>
>>> TAX LIMIT REACHED <<<
</pre>
# Formatting a Number
Notice that the numbers are formatted in a particular way in the output table. You must match this formatting exactly. In order to do so, you can use the format() function. This function was mentioned in the [Constants, variables, and comments
reading](https://adrianapicoral.com/csc-110/basics.html#the-format-method). Here's an example of how you can use this function to match the formatting in the spec.
Say we have a floating point number, like below:
```{python}
#| eval: false
#| echo: true
number = 134567.123
```
Perhaps this is a result you get for one of the dollar values after doing the necessary computations. When printing, you’ll want to adjust the way it is printed in several ways.
## Add a comma
* Set to stop at two decimal points
* Add necessary spacing before the number, so that the table lines up
## Examples for string method `.format()`
Using the comma as a thousands separator:
```{python}
#| eval: true
#| echo: true
'{:,}'.format(1234567890)
```
Establishing numbers of digits to hold space for:
```{python}
#| eval: true
#| echo: true
'{:15,}'.format(10000)
```
Expressing floats with four decimals (the `4` is number of digits after the decimal point, the `f` means it's formatting a float):
```{python}
#| eval: true
#| echo: true
'{:.4f}'.format(4.2353635234)
```
Expressing a percentage with two decimals:
```{python}
#| eval: true
#| echo: true
points = 19
total = 22
'Correct answers: {:.2%}'.format(points/total)
```
Holding space and right aligning the numbers:
```{python}
#| eval: true
#| echo: true
point_1 = 20
print('Correct answers: {:>5,}'.format(point_1))
point_2 = 1000
print('Correct answers: {:>5,}'.format(point_2))
```