Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!

# OCW 6.0 ps1b

By: Adam_M on Nov 15th, 2012  |  syntax: Python  |  size: 1.36 KB  |  views: 49  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. # 6.00 PS1-B Solution
2. # Determines fixed minimum monthly payment needed to finish paying off credit card debt in 1 year
3.
4. # Retrieve input
5. initialBalance = float(raw_input("Enter the outstanding balance on your credit card: "))
6. interestRate = float(raw_input("Enter the annual credit card interest rate as a decimal: "))
7.
8. # Initialize state variables
9. monthlyPayment = 0
10. monthlyInterestRate = interestRate/12
11. balance = initialBalance
12.
13. # Test increasing amounts of monthlyPayment in increments of \$100
14. # until it can be paid off in a year
15. while balance > 0:
16.
17.     monthlyPayment += 10
18.     balance = initialBalance
19.     numMonths = 0
20.
21.     # Simulate passage of time until outstanding balance is paid off
22.     # Each iteration represents 1 month
23.     while numMonths < 12 and balance > 0:
24.
25.         # Count this as a new month
26.         numMonths += 1
27.
28.         # Interest for the month
29.         interest = monthlyInterestRate * balance
30.
31.         # Subtract monthly payment from outstanding balance
32.         balance -= monthlyPayment
33.