我有这段代码,它根据不同的因素显示我需要向学生贷款支付的款项,但我想知道如何显示一个表格告诉我……如果我的程序说我将支付 36 笔 153.02 美元以 6.4% 的利息支付 5000 的贷款,我如何显示一个表格告诉我(153 的付款 1 这是剩余余额,这笔钱用于利息或本金支付,然后相同的付款 2 这是新余额。 .. 等等...)换句话说,一张表格告诉我这 36 笔付款以及我的余额如何随着每次付款而减少。
它不必是一个表格,也许只是一个列表......在付款后列出付款,直到余额为 0 或 - 什么?
这是我到目前为止使用 python 2.7.3 的代码
def calcDebt (principal, interestRate, numPayments, freqPayment):
#This code will make different predictions to pay off student loan
#Input Meanings
'''
Inputs
- interestRate - The Interest Rate of a Loan
- numPayments - The Number of Payments Needed
- principal - The Original Student Loan Amount
- freqPayment - Frequency of Payments Based on Weekly, Monthly, Annually
Returns
- paymentAmount - The Payment Amount Will Be
'''
freqPayment_lookup = {'weekly': 52, 'monthly':12, 'annually':1}
interestRate = float(interestRate) / 100
x = interestRate/freqPayment_lookup[freqPayment]
y = (1.0 + x) ** numPayments
z = x/(y - 1.0)
paymentAmount = (x + z) * principal
return paymentAmount
def main():
a = input('Student Loan Amount: ')
i = input('Student Loan Interest Rate: ')
n = input('Number of Payments: ')
f = None
while f not in ['weekly', 'monthly', 'annually']:
if f:
f = raw_input('Sorry! That is NOT an Option. Please Enter weekly, monthly, or annually: ').lower()
else:
f = raw_input('How Often Do You Want To Make Your Payments? ').lower()
payment = calcDebt(a, i, n, f)
print 'Your %s payment will be %.2f' % (f, payment)
if __name__ == '__main__':
main()
raw_input('Please Press Enter to Exit')
有任何想法吗?