早教吧作业答案频道 -->英语-->
求一个编好的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程序...的网友还看了以下:
已知命题P:方程X^2+mX+1=0有两个不等的负实根.命题Q:方程4X^2+4(m-2)X+1= 2020-04-05 …
已知P:方程x^2+mx+1=0有两个不等的负根,q:方程4x^2+4(m-2)x+1=0无实根, 2020-04-05 …
如图所示,固定容器及可动活塞P都是绝热的,中间有一导热的固定隔板B,B的两边分别盛有气体甲和乙,均 2020-05-14 …
方程x^2/m-1+y^2/m=1表示一个椭圆……设命题P:方程x^2/m-1+y^2/m=1表示 2020-05-16 …
已知关于x的一元二次方程x平方-2x+m-1=0有两个实数根.设p是方程的一个实数根,且满足(p平 2020-05-16 …
数学题求他第一次几个的概率一学生接连参加同一课程的两次考试,第一次几个的概率为p,若第一次及格,则 2020-05-17 …
数学题求他第一次及格的概率一学生接连参加同一课程的两次考试,第一次几个的概率为p,若第一次及格,则 2020-05-17 …
概率论与数理统计浙江第四版答案一学生接连参加同一课程的两次考试,第一次及格的概率是p,若第一次及格 2020-05-17 …
求解一道高数题Y''=1+Y'^2参考答案上是令Y'=p,原方程变为p'=1+p^2y'=p=ta 2020-06-26 …
已知命题p:方程a^2x^2+ax-2=0在[-1,1]上有解.......已知命题p:方程a^2 2020-07-13 …