早教吧作业答案频道 -->其他-->
求python高手解决.Writeapythonprogramthatletstheuserentertheloanamountandloanperiodinnumberofyears.Theprogramwillthendisplaythemonthlyandtotalpaymentsforeachmonthlyinterestratestartingfrom4to8inincrementsof1.
题目详情
求python高手解决.
Write a python program that letsthe user enter the loan amount and loan period in number of years.The program will then display the monthly andtotal payments for each monthly interest rate starting from 4 to 8 inincrements of 1.Calculate the valuesand print the table displaying the interest rate in the first column,themonthly payment in the second column,and the total payment in the thirdcolumn.
Your program should not allow theuser to enter negative amounts for either of the input numbers.Write a function getPositiveFloat that takes a string to be printed at the inputprompt and returns a positive float.getPositiveFloat should loop until it isgiven a positive number and display “Please provide a positive number.” andreprint the prompt anytime the user enters a negative number.Use getPositiveFloat in your main function,for all of yourinput needs
Write a separate function calcMonthly that takes in a rate,anamount and a length of the loan as arguments and returns the monthly payment.
Write a separate function printPayments that calls calcMonthly as part of a loop thatprints the table.
最后的input会变成这样.
Enter the amount(greater than 0) of the loan 10000
Enter the number of years of the loan 5
Rate MonthlyPayment Total Payment
4% $442.02 $26521.11
5% $528.28 $31696.91
6% $618.76 $37125.43
7% $712.29 $42737.54
8% $807.98 $48478.77
Do you want to create another table?
(Enter y for Yes n for No):y
Write a python program that letsthe user enter the loan amount and loan period in number of years.The program will then display the monthly andtotal payments for each monthly interest rate starting from 4 to 8 inincrements of 1.Calculate the valuesand print the table displaying the interest rate in the first column,themonthly payment in the second column,and the total payment in the thirdcolumn.
Your program should not allow theuser to enter negative amounts for either of the input numbers.Write a function getPositiveFloat that takes a string to be printed at the inputprompt and returns a positive float.getPositiveFloat should loop until it isgiven a positive number and display “Please provide a positive number.” andreprint the prompt anytime the user enters a negative number.Use getPositiveFloat in your main function,for all of yourinput needs
Write a separate function calcMonthly that takes in a rate,anamount and a length of the loan as arguments and returns the monthly payment.
Write a separate function printPayments that calls calcMonthly as part of a loop thatprints the table.
最后的input会变成这样.
Enter the amount(greater than 0) of the loan 10000
Enter the number of years of the loan 5
Rate MonthlyPayment Total Payment
4% $442.02 $26521.11
5% $528.28 $31696.91
6% $618.76 $37125.43
7% $712.29 $42737.54
8% $807.98 $48478.77
Do you want to create another table?
(Enter y for Yes n for No):y
▼优质解答
答案和解析
输入贷款总量和贷款年数,显示每个月的还款数额和总还款数额
不是很理解"for each monthly interst rate starting from 4 to 8 in increments of 1",请解释
先粘出来写了开头的代码:
import os
class LOAN_ERROR(Exception):
def __init__(self, message):
self._message = message
def __str__(self):
return self._message
if __name__ == "__main__":
try:
total_loan_money = raw_input("loan amount: ")
loan_period = raw_input("loan period (year): ")
if not isinstance(loan_period, int) or loan_period < 0:
raise LOAN_ERROR("Please provide a positive number.")
不是很理解"for each monthly interst rate starting from 4 to 8 in increments of 1",请解释
先粘出来写了开头的代码:
import os
class LOAN_ERROR(Exception):
def __init__(self, message):
self._message = message
def __str__(self):
return self._message
if __name__ == "__main__":
try:
total_loan_money = raw_input("loan amount: ")
loan_period = raw_input("loan period (year): ")
if not isinstance(loan_period, int) or loan_period < 0:
raise LOAN_ERROR("Please provide a positive number.")
看了 求python高手解决.Wr...的网友还看了以下:
库仑定律和点电荷的表达式理解不太理解o(∩∩)o...书上说,电荷间的库伦力就是电场力,为什么咧? 2020-05-13 …
英语选择题ThiscoatisexpensivethatIcan'taffordtobuyit.A 2020-05-13 …
曾经沧海难为水,曾经沧海又为水.你怎么理解?想听的卜是诗词解释,而是个人看法和理解.o(∩∩)o. 2020-05-16 …
用空间向量解决线线,线面平行问题能不能用具体例子来说分别说明一下,我没有详细学过向量,对于解决解答 2020-05-16 …
同志们,帮忙解决解决这个困扰我很久的物理题吧如图所示,长为L的细线一端固定于O点,另一端系住一个质 2020-05-17 …
1、园林与绿地的区别 2、简述中国古典园林的地形创作特征最近在复习“生态园林设计” 2020-05-17 …
词语搭配,急,十分钟内必须解决解放()解决()解散()解除()开发()开辟()开垦()开展() 2020-05-17 …
关于初三的密度物理问题~~~急急急~~哎,咱滴物理可是差死了...由于没人可以问的,只好上来问一下 2020-06-23 …
谁会这道题:阅读理解.阅读理解.O.Henry,afamousAmericanwriterofsho 2020-11-21 …
希望你们能帮我解决,解决好的话有加奖!一段公路,甲队单独修需要15天完成,乙队单独修要10天完成,丙 2021-01-07 …