''' bal0 = 5000 #balance for month 0 pay0 = bal0 * 0.02 #payment for month 0 unpaidbal0 = bal0 - pay0 #unpaid balance for month 0 rate = 0.18 # yearly interest rate bal1 = unpaidbal0 + ((rate/12)*unpaidbal0) #add interest at beginning of month 1 pay1 = bal1 * 0.02 # make min payment for month 1 unpaidbal1 = bal1 - pay1 #remaining after monthe 1 bal2 = unpaidbal1 + ((rate/12)*unpaidbal1) print monthly like: Month: 1 Minimum monthly payment: 96.0 Remaining balance: 4784.0 round to two decimals print year like Total paid: 96.0 Remaining balance: 4784.0 ''' balance = 4213 annualInterestRate = 0.2 monthlyPaymentRate = 0.04 months = 1 minPay = 0 def minPayment(bal, rate): ''' accepts floats calculatges minimum payment using rate returns float ''' return bal * rate def addInterest(bal, rate): ''' accepts floats calculates new balance with added interest returns float ''' def makePayment(bal, pay): ''' accepts floats subtracts payment from balance returns float ''' balance = makePayment(balance, minPayment(balance, monthlyPaymentRate)) while months <= 12: print 'Month: ' + str(months) print 'Minimum monthly payment: ' + str(minPay) print 'Remaining balance: '+ str(balance) months += 1
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question