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

求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
▼优质解答
答案和解析
输入贷款总量和贷款年数,显示每个月的还款数额和总还款数额
不是很理解"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.")