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

ShannonN

Hi folks, absolute beginner here trying out problem set 1. I've got the code for obtaining the basic information, and the code for the 4 relevant equations, but I can't figure out how to write the code to get the balance after month 1 to become the starting balance for month 2, etc.... can anybody help me with this?

  • one year ago
  • one year ago

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

    Probably, without seeing any code, just assign the balance after month 1 to whatever variable was the starting balance for month 1 and let it run.

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

    use a loop, modify the balance variable in the loop, on the next iteration (month) it will be the balance for the next month

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

    Thanks for the replies! I thought I tried to create a loop with the following code, but it just gives me the same values I get for Month 1 for months2-12. Any clue where I go wrong? Code: #Gets initial values for credit variables from user input bal = float(raw_input('Enter the outstanding balance on your credit card: ')) apr = float(raw_input('Enter the annual interest rate as a decimal: ')) mpr = float(raw_input('Enter the minimum monthly payment rate as a decimal: ')) #Basic equations that use input values to return the new balance minpay = mpr*bal intpaid = apr/12 *bal prinpaid = minpay - intpaid newbalance = bal - prinpaid m = 1 for m in range(1,13): print 'Month: ', m print 'Minimum monthly payment: ', minpay print 'Principle paid: ', prinpaid print 'Remaining balance: ', newbalance bal = newbalance

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

    That last bit should read, bal = newbalance, flush under the last print command...

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

    please use a code pasting site: - http://dpaste.com - http://pastebin.com - http://www.repl.it/ - http://pastie.org - http://codepad.org - http://ideone.com paste your code there and post the link here. select Python syntax highlighting when u paste.

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

    Oh ok, sorry about that!

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

    in your loop, what kind of statements are you executing? Are there any statements in the loop that modify bal or newbalance?

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

    when you think about this problem, what happens over and over again each month?

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

    all of the equations are calculated each month (save for 2), because they all involve a quantity that is changing from month to month--the balance. But I thought that if I wrote bal = newbalance, the next time it runs the loop for month two, it should give me the write result, since the bal for month 2 will now be factored into the variables I ask it to output, if that makes sense.

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

    ... i don't see any calculations in the for loop, just print statements

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

    Ok, so if put the calculations in the loop and THEN put bal=newbalance, that will solve my problem?

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

    Thanks for taking the time to reply, btw...

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

    the calcs need to be in the loop. does mpr change every month or is it constant? "... THEN put bal=newbalance, ... " you could just use bal = bal - prinpaid

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

    mpr is constant... yeah, since i just started this stuff yesterday, i keep wanting to create a new variable every time that variable changes... i forget that bal = bal - prinpaid is a possibility

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

    Thanks so much for your help... i think I can get it to work with the info you gave me!

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

    Yay! it worked...

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

    If you're still here, how do I get python to show the return values with two and only decimal places (it's a float return)?

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

    http://docs.python.org/2.7/library/functions.html#round

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