• API
• FAQ
• Tools
• Trends
• Archive
daily pastebin goal
16%
SHARE
TWEET

OCW 6.0 ps1b

Adam_M Nov 15th, 2012 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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.