如果每年投资和收益固定,那么每年有多少钱
1 # __author: _nbloser 2 # date: 2018/1/21 3 4 def get_money(annual_save=2.4, pecentage=16.8, year=60): 5 print('每年', annual_save, '万,利息', pecentage, '%') 6 final_money = 0 7 for i in range(year): 8 final_money = (annual_save + final_money) * (pecentage / 100 + 1) 9 print('第%2d年:%8.2f 万' % (i + 1, final_money)) 10 11 12 if __name__ == '__main__': 13 get_money(4,13.2)
1 public static void main(String[] args) 2 { 3 // TODO 自动生成的方法存根 4 double finalMoney = getMoney(3.6, 1.156, 60); 5 System.out.println(finalMoney); 6 } 7 public static double getMoney(double annuelSave,double pecentage,int year){ 8 double finalGet = 0; 9 int i; 10 double lilv = 1; 11 System.out.println("每年"+annuelSave+"万,利率"+((pecentage-1)*100)+"%,存"+year+"年的过程拿到的钱"); 12 for(i = 0;i < year;i++){ 13 finalGet = finalGet + annuelSave*pecentage*lilv; 14 lilv = lilv*pecentage; 15 System.out.println("第"+(i+1)+"年:"+finalGet); 16 } 17 return finalGet; 18 }