My first (terrible) program!

Hello, everyone!

I’m just about half way through LPTHW (version 3), and I’m really enjoying my progress so far. I think I remember hearing Zed say in one of the half-way point videos that “I now know enough to write some really terrible python programs”. He’s right!

I took a little break because I’m in the middle of buying a new car, and thought I could use Python to help me figure out my new monthly car payment. The following little program takes values related to the new car purchase (price/apr/terms of loan), and then returns the monthly payment:

Welcome to the payment calculator!
Based on the info you enter, we will
show you the amount of your monthly auto
loan payment. Enter only whole numbers, and
do not use any symbols (e.g., $ or %).\n
Let's get started!

amount = float(input("Enter the negotiated price of you new car: $ "))
trade_in = float(input("Enter the amount of any trade-in vehcile (enter 0 if none): $ "))
tax = float(input("Enter the sales tax rate for your state: % "))
apr = float(input("Enter the APR rate: % "))
term = float(input("Enter the number of years you wish to finance: "))

print("\nHere's what you entered:\n")

print(f"Negotiated price: ${amount}")
print(f"Trade-in value: ${trade_in}")
print(f"Sales tax: {tax}%")
print(f"APR: {apr}%")
print(f"Term: {term} years")

def net_trade_in(new_car, old_car):
    tradein = new_car - old_car
    return tradein

def tax_rate(value, state_rate):
    tax_value = state_rate / 100
    states_taxes = tax_value * value
    return states_taxes

def apr_rate(bottom_line, apr_rate):
    apr_value = apr_rate / 100
    apr_taxes = apr_value * bottom_line
    return apr_taxes

def year_terms(bottom_bottom_line, total_years):
    how_many_months = total_years * 12
    monthly_payment = bottom_bottom_line / how_many_months
    return monthly_payment

tradein_balance = net_trade_in(amount, trade_in)
state_taxes_hurt = tax_rate(tradein_balance, tax) + tradein_balance
apr_also_hurt = apr_rate(state_taxes_hurt, apr) + state_taxes_hurt
monthly_pain = year_terms(apr_also_hurt, term)

print(f"\nNet trade-in balance: ${tradein_balance}")
print(f"Total amount after taxes: ${state_taxes_hurt}")
print(f"Total amount after apr: ${apr_also_hurt}")

print(f"\nMonthly payment: ${monthly_pain}\n")

It’s really easy to break things, so only use whole numbers, no commas, and no symbols ($ or %) at the prompts. I think I got the math right, at least it worked for me and matches what I see for my recent new car purchase.

What really helped me was going REALLY SLOW – especially on each of the functions. And use “print” a lot to find out what’s happening along the way.

Anyway, like I said, it’s a really terrible program, and I’m sure there way better ways to do this, but it’s got me motivated to move forward and finish the book!

1 Like

Hello @latechwriter

I think it looks very good.
Well structured.
Self explaining variables.
And if it does what it is supposed to, it is terrific.

It looks very good for me too. Clear syntax, self explaining variables, functions, etc. And, it helped to solve some problem, awesome!

I like the satiric approach of the following variable state_taxes_hurt :slight_smile:

Thank you for the feedback!

I have no programming experience whatsoever (except a little BASIC on a Commodore 64 in the early 1980s, and Pascal in college), but walked away from all of that many years ago. It’s so cool to revisit all of this now after a long career in a non-technology field.

I was able to write this after just a few weeks of learning Zed’s course and I am super motivated to learn more.

As for variable names, yes, it really helps to use real sounding ones instead of x, y, or z, but I did find that keeping track of all of the variable names can be tricky. I can now see how a good variable taxonomy is important when a program becomes longer and more complex.