Guest User

theode44 solution

a guest
Mar 21st, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. # Retrieve input
  2. initialBalance = float(raw_input("Enter the outstanding balance on your credit card: "))
  3. interestRate = float(raw_input("Enter the annual credit card interest rate as a decimal: "))
  4.  
  5. # Initialize state variables
  6. monthlyPayment = 0
  7. monthlyInterestRate = interestRate/12
  8. balance = initialBalance
  9.  
  10. # Test increasing amounts of monthlyPayment in increments of $100
  11. # until it can be paid off in a year
  12. while balance > 0:
  13.  
  14.     monthlyPayment += 10
  15.     balance = initialBalance
  16.     numMonths = 0
  17.    
  18.     # Simulate passage of time until outstanding balance is paid off
  19.     # Each iteration represents 1 month
  20.     while numMonths < 12 and balance > 0:
  21.        
  22.         # Count this as a new month    
  23.         numMonths += 1
  24.  
  25.         # Interest for the month
  26.         interest = monthlyInterestRate * balance
  27.        
  28.         # Subtract monthly payment from outstanding balance
  29.         balance -= monthlyPayment
  30.  
  31.         # Add interest
  32.         balance += interest
  33.  
  34. # Round final balance to 2 decimal places
  35. balance = round(balance,2)
  36.  
  37. print "RESULT"
  38. print "Monthly payment to pay off debt in 1 year:", monthlyPayment
  39. print "Number of months needed:", numMonths
  40. print "Balance:",balance
Advertisement
Add Comment
Please, Sign In to add comment