Python執行IRR<段考>6/25

照片1

影片

維基百科

程式

pmt = [0,0,0,0] #張園芯程式設計586設定串列list pmt[0]=float(input('張園芯躉繳金額: ')) 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 是一種簡潔易學且功能強大的程式語言,特別適合初學者入門。其語法直觀,代碼可讀性高,讓開發者能夠輕鬆理解並快速實現各種功能。Python 在數據科學、機器學習、網站開發等領域有著廣泛應用,並且擁有豐富的庫和框架,極大提升開發效率。無論是小型項目還是大型應用,Python 都能提供靈活且高效的解決方案,是現代程式設計中不可或缺的工具之一。

留言

此網誌的熱門文章

張園芯2024金融常識測驗

乙班張園芯金融常識onchange改變取代原來onclick按鈕事件 11月 18, 2024

張園芯2024年第三週文件物件模型HTML文件Document