早教吧 育儿知识 作业答案 考试题库 百科 知识分享

求一个编好的python程序,十万火急!Defineafunctionloancalculator(loan,time)thatcalculatesthemonthlypayment,thetotalamounttobepaidandtheamountofinteresttobepaid.Prompttheuserfortheamountofloan(dollars)andtheti

题目详情
求一个编好的python程序,十万火急!
Define a function loan_calculator(loan,time) that calculates the monthly
payment,the total amount to be paid and the amount of interest to be paid.Prompt the
user for the amount of loan (dollars) and the time (years).Use Interest Rate = 4%.Formula
for interest calculation = loan amount * interest rate (0.04) * number of years.Use floats for
this problem and format numbers to 2 decimal places
Here is how it runs:
>>> What is amount of loan?100000
Number of years to pay off the loan?20
Monthly payment is:750.00
Total interest paid:80000.0
Total amount paid:180000.0
>>> What is amount of loan?23000
Number of years to pay off the loan?5
Monthly payment is:460.00
Total interest paid:4600.0
Total amount paid:27600.0
▼优质解答
答案和解析
'''
Created on 2011-9-14
@author: legendxx
'''
rate =0.04
if __name__ == '__main__':
amount = int(raw_input("What is amount of loan?"))
year = int (raw_input("Number of years to pay off the loan?"))

interest = amount*rate*year
total = amount + interest
monthly_payment = total/(year*12)

print "Monthly payment is:%.2f"%monthly_payment
print "Total interest paid:%.2f"%interest
print "Total amount paid:%.2f"%total
可在2.x环境下运行,与3.x不兼容的,使用的时候请注意.
另外,利息的公式是按照提供的公式计算的,实际银行采用的是复利,应该比这个实际利率要高.