TQC+ 程式語言 Python 3 _ 309 存款總額

說明:
請使用迴圈敘述撰寫一程式,提示使用者輸入金額(如10,000)、年收益率(如5.75),以及經過的月份數(如5),接著顯示每個月的存款總額。
提示:四捨五入,輸出浮點數到小數點後第二位
舉例:
假設您存款$10,000,年收益為5.75%。
過了一個月,存款會是:10000 + 10000 * 5.75 / 1200 = 10047.92
過了兩個月,存款會是:10047.92 + 10047.92 * 5.75 / 1200 = 10096.06
過了三個月,存款將是:10096.06 + 10096.06 * 5.75 / 1200 = 10144.44
以此類推。

範例輸入:
50000
1.3
5
範例輸出:
Month    Amount
  1     50054.17
  2     50108.39
  3     50162.68
  4     50217.02
  5     50271.42
程式碼:
amount = int( input() )
rate = abs( eval( input() ) )
month = int( input() )

print( 'Month \t  Amount' )

for i in range( 1, month+1 ):
    total = amount + ( amount*rate ) / 1200
    amount = total
    print( '{:3d} \t {:.2f}'.format( i, total ) )

沒有留言:

張貼留言