Advertisement
petrissimo

OCW 6-00 sc. PS1 (Decimal option)

Nov 7th, 2012
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. from decimal import * # Decimal module
  2. getcontext().prec = 28
  3.  
  4. balance = float(raw_input('Enter the outstanding balance on the credit card: '))
  5. balanceStr = float(0) #Decimal module can't work with floats, needs to convert to string
  6.  
  7. annualRate = float(raw_input('Enter the annual interest rate on the credit card: '))
  8.  
  9. minPaymentRate = float(raw_input('Enter the minimum monthly payment rate on the credit card: '))
  10.  
  11.  
  12. print("\n")
  13.  
  14. monthly_rate = annualRate/12
  15.  
  16. print("\n")
  17.  
  18. months = int(0)
  19. minMonPay = float (0) #minimum monthly pay
  20. minMonPayStr = float (0)
  21. intsPaid = float (0) #interests paid
  22. principalPaid = float(0)
  23. principalPaidStr = float(0)
  24. totalAmountPaid = float(0)
  25. totalAmountPaidStr = float(0)
  26.  
  27.  
  28. while months<12:
  29. months = months+1
  30. print 'month:', months
  31.  
  32. minMonPay = (minPaymentRate * balance)
  33. minMonPayStr = str(minMonPay)
  34. print 'minimum monthly payment:', '$', Decimal (minMonPayStr).quantize(Decimal('0.01'), rounding=ROUND_UP)
  35.  
  36. intsPaid = monthly_rate * balance
  37. principalPaid = minMonPay - intsPaid
  38. principalPaidStr = str(principalPaid)
  39. print 'principal Paid', '$', Decimal (principalPaidStr).quantize(Decimal('0.01'), rounding=ROUND_UP)
  40.  
  41. balance = (balance - (principalPaid))
  42. balanceStr = str(balance)
  43. print 'remaining balance', '$', Decimal (balanceStr).quantize(Decimal('0.01'), rounding=ROUND_UP)
  44.  
  45. totalAmountPaid = (totalAmountPaid + minMonPay)
  46.  
  47. print("\n")
  48.  
  49. print "RESULT\n"
  50. print 'remaining balance', '$', Decimal (balanceStr).quantize(Decimal('0.01'), rounding=ROUND_UP)
  51. totalAmountPaidStr = str(totalAmountPaid)
  52. print 'totalAmountPaid', '$', Decimal (totalAmountPaidStr).quantize(Decimal('0.01'), rounding=ROUND_UP)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement