Mary Dickson Diaz

Code, Life, Learning

question set 2: things get interest-ing

First, an update on the MIT Python course — y’all, my MOM is taking it too. How cool is that? Mom has a full career behind her in computer programming, technical writing and online learning, and she’s also Mensan-level puzzler, so naturally she is 1) kicking my ass and 2) taking issue with some of the courseware issues (and by extension, other people in the class).

I agree that the “discussion” aspects of the class are not great, something like 1,000+ 50,000+ people are enrolled so it’s best to take the comments with a grain of salt, and find some support that you trust. Quick aside, the guy who was like: “What is paying off credit card debt?? I do not understand this concept” — maybe has never known debt or has never known credit cards, or just didn’t understand how the question was worded? Anyway it made me chuckle.

So, this MOOC format probably doesn’t take advantage of best practices for online learning. But it’s free and exposing lots of people to something new, so I suppose you get what you pay for. I’d still recommend the class, just not as a stand-alone or a substitution for a full-on college degree (I have one already).

Ok, back to problem set 2 — paying off credit card debt. I am exceptionally proud that I completed all the programs in this set totally by myself, and for something more useful than “find ‘beeeegh.'” SO PROUD in fact that I failed to read the directions and wrote an entirely different program from the one they asked for. My friend Ian commiserates:

However, once I had the basic mechanisms working, it wasn’t too hard to adjust for what the problem set was looking for. Before I share the code, I want to share my “pre-work,” or how I figured it out. Basically, given the problem of “if you owe $x on a card with a y% interest rate, how much should you pay each month in a flat rate (same amt each month) to be debt-free in a year?”

Before I put anything in the code window, I took out pencil and paper and figured it out. This stuff happens in real life, after all, and I’m not great at math but I’m pretty good at guess-and-check. So I invented a scenario where a person owes $3,000 at 20% interest, started with a guess of $300/month (total owed plus interest divided by 12). $300 doesn’t work, of course, because interest gets calculated MONTHLY and that is confusing and I don’t know how to do it on paper, but luckily I had just written a program in the first part of the question to calculate exactly that. So I just *made that program a function*, took my guess and called the function upon it to see how much I would be over or under-paying at the end of the year.

python interest Q

At $300 a month, I’m overpaying by $356, so let’s divide that by 12 and subtract that amount each month to see where that lands us. My new guess is $271, I put it through the same function (remainingbalance), and now I owe $31. Divide that by 12, add 1/12th each month, new guess is $273, and repeat until we hit zero (or close enough).

After doing this manually, I went back and figured out where I needed the computer to loop (when did I start looping?), and wound up with the following:

Please do not go out and amass a bunch of credit card debt to test this — I assure you it works!

In all sincerity, I have seen this advice of “sketch out the program first” and it helped me with this particular problem.

Next up, hangman!



  1. testing html for kevin. looky, a lemur
    *edit — comments without html work just fine, comments with any html go to a “page not found” and do not post

  2. oh hey, here’s another comment.

Leave a Reply

© 2023 Mary Dickson Diaz

Theme by Anders NorenUp ↑