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

MakaiM

Help Needed with Debugging P1! Hey guys, my code is producing weird output...any idea why this may be?

  • 10 months ago
  • 10 months ago

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

    ## Problem Set 1 ## Gather user input outstandingBalance = float(raw_input("Please enter the outstanding balance on your credit card: ")) interestRate = float(raw_input("Please enter the interest rate on your credit card as a decimal: ")) minPayment = float(raw_input("Please enter the minimum monthly payment on your credit card as a decimal: ")) ##Initialize variables currentMinPayment = 0.0 principlePaid = 0.0 interestPaid = 0.0 month = 1 remainingBalance = 0.0 ##Run loop while month<=12: print(type(currentMinPayment)) print(type(minPayment)) print(type(outstandingBalance)) currentMinPayment = round(minPayment * outstandingBalance,2) interestPaid = round (interestPaid + ((interestRate/12)*outstandingBalance),2) principlePaid = round(principlePaid + (currentMinPayment - interestPaid), 2) outstandingBalance = round((outstandingBalance - principlePaid), 2) ##Make all into strings currentMinPayment = str(currentMinPayment) interestPaid = str(interestPaid) principlePaid = str(principlePaid) outstandingBalance = str(outstandingBalance) month = str(month) ##Print all out print ("Month: " + month) print ("Minimum monthly payment: $" + currentMinPayment) print ("Principle paid: $" + principlePaid) print ("Remaining balance: $" + outstandingBalance) ##Change month to int and increment month month = int(month) month = (month +1) ##Change then back to floats currentMinPayment = float(currentMinPayment) interestPaid = float(interestPaid) principlePaid = float(principlePaid) outstandingBalance = float(outstandingBalance) month = int(month)

    • 10 months ago
  2. rsmith6559
    Best Response
    You've already chosen the best response.
    Medals 0

    I don't like converting variables to strings and back to numbers. Unless the course requires it, I say don't do it. You can have str( aFloatOrInt ) in a print statement/function. I've also at times had variables like numberString, which is the string of my number for printing.

    • 10 months ago
  3. MakaiM
    Best Response
    You've already chosen the best response.
    Medals 0

    I was having trouble with print statements with the variables as strings, i.e. print "Month: " + month, when month is an int, was resulting in an error, thus the conversions

    • 10 months ago
  4. MakaiM
    Best Response
    You've already chosen the best response.
    Medals 0

    i totally agree, not ideal

    • 10 months ago
  5. eSpeX
    Best Response
    You've already chosen the best response.
    Medals 2

    Not sure if it's in the conversion or the casting back, but you have a multiplier being added to your values.

    • 10 months ago
  6. eSpeX
    Best Response
    You've already chosen the best response.
    Medals 2

    Put in 2500 as a minimum payment and it prints Minimum monthly payment: $250000.0

    • 10 months ago
  7. eSpeX
    Best Response
    You've already chosen the best response.
    Medals 2

    Oh, because you are multiplying it by the outstanding balance: currentMinPayment = round(minPayment * outstandingBalance,2) I would say that you need to hammer out your logic before you worry too much about formatting on your printout. Once you have it working mathematically, then format your output.

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

    use a comma instead of a plus sign in the print statements. what is weird about the results

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

    http://dpaste.com/1243145/

    • 10 months ago
  10. eSpeX
    Best Response
    You've already chosen the best response.
    Medals 2

    How about the fact that you input a monthly payment of $0.05 and it makes it $50.00? You would never be able to pay off $400ish in 12 months, at 10%, with only a nickel paid each month.

    • 10 months ago
  11. MakaiM
    Best Response
    You've already chosen the best response.
    Medals 0

    Figured it out - thanks guys!

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

    @eSpex .... the prompt is a bit misleading - that is supposed to be asking for a monthly payment Rate.

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