Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

medicrobosn Group Title

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/

  • one year ago
  • one year ago

  • This Question is Closed
  1. simmoleon Group Title
    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.

    • one year ago
  2. deerbane Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    That looks like mine.

    • one year ago
  3. Hellvince Group Title
    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).

    • one year ago
  4. Hellvince Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • one year ago
  5. bwCA Group Title
    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?

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.