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

sidonsoft Group Title

my code is off by 10 compared to other test cases, but not all the time, any ideas? balance = 4157 annualInterestRate = 0.18 payment = 10 def payforyear(x): count = 0 while count < 12: x = (x - payment) + (x*(annualInterestRate / 12)) count = count + 1 if count == 12: return x while payforyear(balance) > 0: payment = payment + 10 else: print ('Lowest payment: ' +str(payment) )

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. Chris2332 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Why do you check if count == 12? Since the while loop will end anyway when the count reaches 12, you can just return the value!

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

    if i recall correctly, if i didn't check count 12 and put the return x line in it returned the result after one iteration of the loop

    • 2 years ago
  3. msmithhnova Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    Well, the main thing that is wrong is the formula (x-paymnet)+(x*(annualInterestRate/12)) If you check instructions it is (xipayment)*(1-(annualInterestRate/12)) This will fix your problem but stylistically using variables defined outside the function is bad practice unless absolutely necessary.

    • 2 years ago
  4. Chris2332 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Sorry just to be clear, which exercise are you trying to solve? I guess it's the second one!

    • 2 years ago
  5. msmithhnova Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    That should read (x-payment)...

    • 2 years ago
  6. msmithhnova Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    And (1+(... not minus

    • 2 years ago
  7. Chris2332 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    x = (x - payment) *(1+annualInterestRate / 12) should do the trick I guess

    • 2 years ago
  8. sidonsoft Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Yes, it does actually problem is I have no idea how, and why i got it wrong in the first place. I have looked at that area of the code more than a few times over the past 12 hours I have been working on it. I have this weird feeling that my solution is very very very far from other peoples solutions.

    • 2 years ago
  9. msmithhnova Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    Yes and as chris said previously the if count==12 is not necessary as long as the return statement is lined up with the while, I tested it too.

    • 2 years ago
  10. sidonsoft Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    yes thank you for that Chris, I am still getting my head around logic and python work flow. I was scratching my head with the while statement and indentation for a good couple of hours.

    • 2 years ago
  11. msmithhnova Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    Indentation in python is very important to the meaning and this is a good reason for beginners to learn python because it forces good habits of indentation. Which isn't necessary in some languages but always recommended.

    • 2 years ago
  12. Chris2332 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Ditto!

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