Python #2: Savings Calculator

This first Python project is for a savings calculator.

The program should calculate how much a person can save in a year based on their income, hours worked, and cost of living. So that’s only 3 factors we gotta work with.

We’ll start with an intro string that says “Hello Bob”, but we have to use variables and combine them

So the first variable will be the greeting, “hello”

greeting = "Hello "

A major key with this is the space after “hello”. Without it, the output would put the 2 words together. Whatever happens inside the quotes is transferred to the output.

Next, we have the name variable, “Bob”

name = "Bob"

Then we put it together with the ‘print’ command

greeting = "Hello "
name = "Bob"
print(greeting + name)

Output: Hello Bob

Now let’s build this calculator!

Bob makes $20/hour and he works 40 hours a week. So we’ll set those numbers to their own variables and then set a weekly income variable to multiply them.

hourly_wage = 20
hours_per_week = 40
income_per_week = (hourly_wage * hours_per_week)

Bob makes $800 per week. Now we could’ve used the print command to see the answer, but we’re not done yet. We know what the number is though

Bob works 48 weeks per year. So we’ll set that variable. Then we multiply that by the income per week to calculate his yearly income, which will be a variable itself.

weeks_per_year = 48
income_per_year = (income_per_week * weeks_per_year)

Bob makes $38400 per year.

Now that his salary’s been calculated, we’re gonna put it all together. We print the ‘name’ variable, and combine that with a string that holds the possessive ‘s’ and “yearly income is”. Then we print the income per year variable.

name = "Bob"

hourly_wage = 20
hours_per_week = 40
income_per_week = (hourly_wage * hours_per_week)
weeks_per_year = 48
income_per_year = (income_per_week * weeks_per_year)

print(name + "'s yearly income is:")
print(income_per_year)

Output: Bob's yearly income is:
$38400

Now onto his bills. He has to spend $400/week, so we create that variable. Then we make another one for his yearly expenses.

spend_per_week = 400
spend_per_year = spend_per_week * 52

We only got one more step now, calculate his yearly savings. Subtract the yearly spending from the yearly income

savings_per_year = (income_per_year - spend_per_year)

And finally, we print all our calculations and use strings to label them.

# --- Display a greeting ---
greeting= "Hello "
name="Bob"
print(greeting+name)
# --- Calculate the yearly income ---

hourly_wage = 20
hours_per_week = 40
income_per_week = (hourly_wage * hours_per_week)
weeks_per_year = 48
income_per_year = (income_per_week * weeks_per_year)

print(name + "'s yearly income is:")
print(income_per_year)


# --- Calculate the yearly spend ---
spend_per_week = 400
spend_per_year = spend_per_week * 52
print(name + "'s yearly spend is:")
print(spend_per_year)


# --- Calculate the yearly savings ---
savings_per_year = (income_per_year - spend_per_year)
print (name + "'s yearly savings:")
print(savings_per_year)

Output: Hello Bob
Bob's yearly income is:
38400
Bob's yearly spend is:
20800
Bob's yearly savings:
17600

The hashtags & dashes are comments. This keeps it organized for other programmers who might have to work on this. Imagine if all these commands were stacked on top each other.

And that’s it for my first Python project, even though it’s basic. See yall next time.

Leave a comment