## 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/

1. simmoleon

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

That looks like mine.

3. Hellvince

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

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

5. bwCA

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