题目:
编写程序,输入本金、年利率和年份,计算复利(结果保留2位小数)。运行效果如下:
请输入本金:2000
请输入年利率:5.6
请输入年份:5
本金利率和为:2626.3
1.引入库
代码如下(示例):
# 编写程序,输入本金、年利率和年份,计算复利(结果保留2位小数)。运行效果如下: # 请输入本金:2000 # 请输入年利率:5.6 # 请输入年份:5 # 本金利率和为:2626.33 # 复利的计算公式是:s=p(1+i)^n principal = int(input("请输入本金:")) annual_interest = float(input("请输入年利率:")) year = int(input("请输入年份:")) amount = principal*(1+annual_interest/100)**year print("本金利率和为:%.2f"%amount)