早教吧作业答案频道 -->英语-->
求一个编好的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
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不兼容的,使用的时候请注意.
另外,利息的公式是按照提供的公式计算的,实际银行采用的是复利,应该比这个实际利率要高.
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不兼容的,使用的时候请注意.
另外,利息的公式是按照提供的公式计算的,实际银行采用的是复利,应该比这个实际利率要高.
看了 求一个编好的python程序...的网友还看了以下:
程序编制有三个层次,其实施顺序应是A.编码、画程序框图、测试B.编码、写程序文档、排错C.编码、测试 2020-05-23 …
完成一个汇编语言用户程序的编制和调试,通常需四个步骤:首先用编辑程序编出用户的源程序,然后通 2020-05-23 …
解释程序边逐条解释边逐条执行,不保留机器码的目标程序,编译方式是使用编译程序把源程序编译成机 2020-05-24 …
程序编制有三个层次,其实施顺序应是()。A.编码、画程序框图、测试B.编码、写程序文档、排错C.编码 2020-05-24 …
程序编制有3个层次,其实施顺序应是()。A.编码、画程序框图、测试B.编码、写程序文档、排错C.编码 2020-05-24 …
C语言程序设计题目帮忙答一下3、题型:单选题分值:12C语言程序编译时,程序中的注释部分()。选项1 2020-11-23 …
5一般编写并执行C程序的过程,第一步应该是:.A使用连接程序进行连接,把.obj文件以及需要的库函数 2020-11-23 …
高级语言编制的程序()A.比机器语言编制程序更优化,执行效率更高。B.经过编译程序编译后,才能被CP 2020-11-23 …
五笔打字的时候,如果遇到所拆字根的编码顺序和该字的书写顺序不一至的时候,怎么办?如,瓦的书写顺序是: 2020-12-02 …
小明给一个动点P编写了一个运动程序:给参量m赋予一个值后,点P将按如下设置的横、纵坐标程序运动.参量 2020-12-31 …