长春网站制作最新招聘信息,佛山公司做网站,百度一下你知道,余姚建站公司目录
实验目的
实验内容…目录
实验目的
实验内容
描述
输入格式
输出格式 标准答案
我的答案01
我的答案02 实验目的
理解求解等额本息分期付款和等额本金分期付款的计算方法。熟练运用Python列表。理解if分支工作原理。理解for循环工作原理。
实验内容 描述
购买房屋或大宗家电时很多时候可以分期付款还款方式分为等额本息和等额本金两种
等额本息Average Capital Plus Interest:ACPI还款公式:
每月还款额贷款本金*月利率*(1月利率)**总还款月数/((1月利率)**总还款月数-1)
等额本金Average Capital:AC还款公式:
每月还款额贷款本金/总还款月数(贷款本金-累计已还款本金)*月利率
设计一个程序计算分期付款时每一期的应还款额还款方式输入错误时输出“还款方式输入错误”。
输入格式
4行输入
第1行输入一个浮点数表示贷款本金
第2行输入一个整数表示分期月数
第3行输入一个字符串表示还款方式限定只能输入ACPI或AC分别表示等额本息和等额本金
第4行输入一个浮点数表示月利率
输出格式
输出每月还款额等额本金方式时输出的数字间用逗号分隔(用round()函数保留2位小数)
还款方式输入错误时输出“还款方式输入错误”
示例 1
输入
6800
12
AC
0.006输出[607.47, 604.07, 600.67, 597.27, 593.87, 590.47, 587.07, 583.67, 580.27, 576.87, 573.47, 570.07] 标准答案
price,month,mode,rate float(input()),int(input()),input(),float(input())
if mode AC:ls []for i in range(month):repayment price / month (price - price / month * i) * ratels.append(round(repayment,2))print(ls)
elif mode ACPI:repayment price * rate * (1 rate) ** month /((1 rate) ** month - 1)print(round(repayment,2))
else:print(还款方式输入错误)
我的答案01
totalMoneyfloat(input())
totalMonthint(input())
Wayinput()
monthlyRatefloat(input())
everyMoney[]
if WayACPI:tempMoneytotalMoney*monthlyRate*(1monthlyRate)**totalMonth/((1monthlyRate)**totalMonth-1)print(round(tempMoney,2))elif WayAC:for i in range(totalMonth):tempMoneytotalMoney/totalMonth(totalMoney-totalMoney/totalMonth*i)*monthlyRateeveryMoney.append(round(tempMoney,2))print(everyMoney)
else:print(还款方式输入错误)
我的答案02
def calculate_payment(): # 输入贷款本金 totalMoney float(input()) # 输入分期月数 totalMonth int(input()) # 输入还款方式 Way input() # 输入月利率 monthlyRate float(input()) everyMoney[]if Way not in [ACPI, AC]: print(还款方式输入错误) return if Way ACPI: # 等额本息还款公式 tempMoneytotalMoney*monthlyRate*(1monthlyRate)**totalMonth/((1monthlyRate)**totalMonth-1)print(round(tempMoney,2))else: # 等额本金还款公式 for i in range(totalMonth):tempMoneytotalMoney/totalMonth(totalMoney-totalMoney/totalMonth*i)*monthlyRateeveryMoney.append(round(tempMoney,2))print(everyMoney)calculate_payment()