胡庭毓Python執行IRR

嵌入胡庭毓解說影片

嵌入WIKIPEDIA二分法

"/>
pmt = [0,0,0,0] #胡庭毓程式設計586設定串列list
pmt[0]=float(input('躉繳金額: '))#floot函數轉化為實數(浮點數)
for nper in range(1,4):
    pmt[nper] = float(input('第'+str(nper)+'期回收: '))
def npv(rate):
    y = - pmt[0]
    for j in range(1,4):
        y = y + pmt[j]/(1+rate)**j
    return y
a, b, gap, f = 0.0, 1.0, 9.0, 9.0
maxerror = 0.000001
loopNumber = 1
while (gap > maxerror and abs(f) > maxerror and loopNumber < 100):
    loopNumber+=1
    c = (a+b)/2;
    f = npv(c);
    if ( abs(f) > maxerror and gap > maxerror):
        if ( f>0 ):
            a = c
        else:
           b = c
        gap = b-a;
print('胡庭毓報酬率: ', c)
print('胡庭毓淨現值: ', f)
print('胡庭毓迴圈次數: ', loopNumber)

心得

在學了一學期的程式設計後,我更加了解了程式設計軟體如何運作

留言

這個網誌中的熱門文章

胡庭毓python,tkinter,Entry建構輸入工具,pop移除串列元素 3月 31, 2025