Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

medicrobosn

  • 2 years ago

Looking for help on anyway that I might be able to better optimize this simple program for the 6.00sc Problem set1 I have posted the code on http://dpaste.com/hold/1322328/

  • This Question is Closed
  1. simmoleon
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Looks good to me, just in case you didn't know you can use %s in print statements to make it easier to format. Have a look here: http://stackoverflow.com/questions/5954260/default-substituting-s-in-python-scripts Also, you can abbreviate x=x+1 with x += 1.

  2. deerbane
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    That looks like mine.

  3. Hellvince
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm not a big fan of "while" loop when you just want to scope through a predetermined set of values. It is easy to get stuck in an infinite loop (but thats not the case here). I would go for a "for" loop : for x in range(1,13): intpaid = apr/12*balance princ = balance*minpayrate-intpaid print 'Minimun amount you must pay is ' +str (round(balance*minpayrate,2)) print 'Interest paid in month '+str (x),': $' +str (round(intpaid,2)) print 'Principal paid in month '+str (x),': $' +str (round(princ,2)) balance = balance -princ print 'Remaining balance is: ' +str (round(balance,2)) total = total + (princ + intpaid) print 'Amount paid out over '+str(x) +' months is $'+str (round(total,2)) BTW, kudos for calling round() on results. I dont understand why ppl keep rounding values at the very start of the program, as it impacts results precision (however, i agree it is sometime desirable).

  4. Hellvince
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Maybe thats better if i give a readable output: http://dpaste.com/1323844/

  5. bwCA
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    i don't see any reason to optimize your solution. is it running too slow?

  6. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy