求一个编好的python程序,十万火急!

求一个编好的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
布衣傲云 1年前 已收到1个回答 举报

ttsk79 幼苗

共回答了14个问题采纳率:71.4% 举报

'''
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不兼容的,使用的时候请注意.
另外,利息的公式是按照提供的公式计算的,实际银行采用的是复利,应该比这个实际利率要高.

1年前 追问

3

布衣傲云 举报

thank you very much. 但是为什么我做的时候那个year是个invalid syntax?

举报 ttsk79

你是用的我的程序吗?还是你自己做的程序?如果是你的程序把你的程序也贴出来吧。
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 0.863 s. - webmaster@yulucn.com