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

TuringTest

Python: Why can't I insert print statements to debug this?

  • one year ago
  • one year ago

  • This Question is Closed
  1. TuringTest
    Best Response
    You've already chosen the best response.
    Medals 0

    balance = 320000 annualInterestRate = 0.2 epsilon=.01 low=balance/12.0 monthlyInterestRate=annualInterestRate/12.0 high=balance*(1+monthlyInterestRate)**12/12.0 payment=(high+low)/2.0 newBalance=balance while abs(balance-newBalance)>epsilon: newBalance=balance for count in range(12): newBalance=(newBalance-payment)*(1+monthlyInterestRate) if balance>newBalance: low=payment else: high=payment payment=(high+low)/2.0 print('Lowest Payment: '+str(round(payment, 2)))

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

    the output is coming out too high, but I can't debug it because it only will let me put print statements in at the end for some reason. I would like to put one up between lines 9 and 10 to track the balance, and another at the end to track payment. Any ideas?

    • one year ago
  3. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    Why can't you debug? I'm not too sure about Python nor the editor you are using, but if you want to do things like debug you will need a good IDE, which I also recommend. I'll take a look later to see if I find a mistake tho.

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

    high=balance*(1+monthlyInterestRate)**12/12.0 what's this **?

    • one year ago
  5. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    Also I would surround by brackets if that is what should happen. (balance*(1+monthlyInterestRate)**12)/12?? I mean I shouldn't have to tell a math wizz like you that, so I'm assuming you did this on purpose, but who knows... that ** is something I'm more konfused about :P

    • one year ago
  6. TuringTest
    Best Response
    You've already chosen the best response.
    Medals 0

    The program is to use bisection search to find the minimum monthly payment required to pay off some debt "balance" within one year . high=balance*(1+monthlyInterestRate)**12/12.0 this is the maximum yearly payment could be imagining we didn't pay off anything at any month and the interest accrues by a factor of 1+monthlyInterestRate each month, then the monthly payment is given by dividing by 12 months. And yeah, I tried the parentheses bit.

    • one year ago
  7. TuringTest
    Best Response
    You've already chosen the best response.
    Medals 0

    what is an IDE ?

    • one year ago
  8. TuringTest
    Best Response
    You've already chosen the best response.
    Medals 0

    ** raises to a power btw

    • one year ago
  9. eSpeX
    Best Response
    You've already chosen the best response.
    Medals 0

    IDE = Integrated Development Environment

    • one year ago
  10. TuringTest
    Best Response
    You've already chosen the best response.
    Medals 0

    Problem solved, I had all sorts of horrible things going on. the worst being that I defined newBalance=balance at the beginning, so the next line while abs(balance-newBalance)>epsilon was never true, so the thing wasn't even running the body of the program :P I won't type the corrected program as it is an answer to the MITx thing, but I did get it :)

    • 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.