財務大數(shù)據(jù)基礎(第二版)課件 項目五 Python循環(huán)結構程序設計_第1頁
財務大數(shù)據(jù)基礎(第二版)課件 項目五 Python循環(huán)結構程序設計_第2頁
財務大數(shù)據(jù)基礎(第二版)課件 項目五 Python循環(huán)結構程序設計_第3頁
財務大數(shù)據(jù)基礎(第二版)課件 項目五 Python循環(huán)結構程序設計_第4頁
財務大數(shù)據(jù)基礎(第二版)課件 項目五 Python循環(huán)結構程序設計_第5頁
已閱讀5頁,還剩40頁未讀 繼續(xù)免費閱讀

付費下載

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

項目五Python循環(huán)結構程序設計目標理解循環(huán)結構理解for循環(huán)和while循環(huán)的用法了解continue和break的用法任務一存儲2020年到2023年的相關財報數(shù)據(jù)相關知識各年數(shù)據(jù)的存儲全部數(shù)據(jù)的存儲年

度2020年2021年2022年2023年凈利潤165010221.56202662270.20244060018.62-7834747.02期初凈資產(chǎn)2761772535.392885521135.423312422711.803560111655.87期末凈資產(chǎn)2885521135.423312422711.803560111655.873429031128.43各年數(shù)據(jù)的存儲每年數(shù)據(jù)如何存儲?年

度2020年2021年2022年2023年凈利潤165010221.56202662270.20244060018.62-7834747.02期初凈資產(chǎn)2761772535.392885521135.423312422711.803560111655.87期末凈資產(chǎn)2885521135.423312422711.803560111655.873429031128.43各年數(shù)據(jù)的存儲每年數(shù)據(jù)如何存儲?年

度2020年凈利潤165010221.56期初凈資產(chǎn)2761772535.39期末凈資產(chǎn)2885521135.42各年數(shù)據(jù)的存儲每年數(shù)據(jù)存入一個字典年

度2020年2021年2022年2023年凈利潤165010221.56202662270.20244060018.62-7834747.02期初凈資產(chǎn)2761772535.392885521135.423312422711.803560111655.87期末凈資產(chǎn)2885521135.423312422711.803560111655.873429031128.43cSoftDict1cSoftDict2cSoftDict3cSoftDict4["profit"]["beginAsset"]["endAsset"]["period"]各年數(shù)據(jù)的存儲每年數(shù)據(jù)存入一個字典

全部數(shù)據(jù)的存儲用一個列表存儲四個字典任務二使用for循環(huán)計算各年凈資產(chǎn)收益率相關知識for循環(huán)range函數(shù)for循環(huán)控制語句塊的重復執(zhí)行for和in都是關鍵字迭代器是Python語言中的重要機制之一for循環(huán)變量in迭代器:

語句塊

循環(huán)的控制結構,它控制for中語句塊的執(zhí)行次數(shù)循環(huán)體此處為縮進,縮進量通常為4個字符迭代器是一個值序列,或值集合迭代器中的值的個數(shù)就是for循環(huán)的次數(shù)for循環(huán)循環(huán)次數(shù)i值循環(huán)體10i的值為021i的值為132i的值為243i的值為3示例for循環(huán)循環(huán)次數(shù)i值循環(huán)體110i=10213i=13316i=16417i=17示例for循環(huán)循環(huán)次數(shù)item值循環(huán)體1’a’item=a2’b’item=b3’abc’item=abc4100item=100示例range()函數(shù)產(chǎn)生指定范圍的一系列值常作為for循環(huán)的迭代器range(n)range(m,n)range(m,n,d)省略m和d,m=0,d=1序列:0,1,2,3,…,n-1,即從0至n(不包括n)n≤0的時候序列為空省略d,d=1序列:m,m+1,m+2,…,n-1,即從m至n(不包括n)m≥n時序列為空序列:m,m+d,m+2d,…,即從m開始,依次按步長值d遞增(若d為負則遞減),直至那個最接近但不包括n的等差值結束for循環(huán)示例一cSoftList1[3]cSoftList1[2]cSoftList1[1]年

度2020年凈利潤165010221.56期初凈資產(chǎn)2761772535.39期末凈資產(chǎn)2885521135.42cSoftList1[0]cSoftList10,1,2,32,31,3for循環(huán)示例二["period"]2020年["period"]2021年["profit"]165010221.56["profit"]202662270.20["beginAsset"]2761772535.39["beginAsset"]2885521135.42["endAsset"]2885521135.42["endAsset"]3312422711.80cSoftList2[1]cSoftList2[0]cSoftList20,1使用循環(huán)從列表cSoftList中提取數(shù)據(jù)"period"2020年"period"2021年"period"2022年"period"2023年"profit"165010221.56"profit"202662270.20"profit"244060018.62"profit"-7834747.02"beginAsset"2761772535.39"beginAsset"2885521135.42"beginAsset"3312422711.80"beginAsset"3560111655.87"endAsset"2885521135.42"endAsset"3312422711.80"endAsset"3560111655.87"endAsset"3429031128.43cSoftList[1]cSoftList[0]cSoftListcSoftList[3]cSoftList[2]keyvaluekeyvaluekeyvaluekeyvalue0,1,2,3使用循環(huán)從列表cSoftList中提取數(shù)據(jù)程序流程圖使用循環(huán)從列表cSoftList中提取數(shù)據(jù)"period"2020年"period"2021年"period"2022年"period"2023年"profit"165010221.56"profit"202662270.20"profit"244060018.62"profit"-7834747.02"beginAsset"2761772535.39"beginAsset"2885521135.42"beginAsset"3312422711.80"beginAsset"3560111655.87"endAsset"2885521135.42"endAsset"3312422711.80"endAsset"3560111655.87"endAsset"3429031128.43cSoftList[1]cSoftList[0]cSoftListcSoftList[3]cSoftList[2]keyvaluekeyvaluekeyvaluekeyvalue2,30,2使用循環(huán)從列表cSoftList中提取年度數(shù)據(jù)"period"2020年"period"2021年"period"2022年"period"2023年"profit"165010221.56"profit"202662270.20"profit"244060018.62"profit"-7834747.02"beginAsset"2761772535.39"beginAsset"2885521135.42"beginAsset"3312422711.80"beginAsset"3560111655.87"endAsset"2885521135.42"endAsset"3312422711.80"endAsset"3560111655.87"endAsset"3429031128.43cSoftList[1]cSoftList[0]cSoftListcSoftList[3]cSoftList[2]keyvaluekeyvaluekeyvaluekeyvalue0,1,2,3cSoftList[0]cSoftList[1]cSoftList[2]cSoftList[3]cSoftList[0]cSoftList[1]cSoftList[2]cSoftList[3]使用循環(huán)提取2023年度的財報數(shù)據(jù)"period"2020年"period"2021年"period"2022年"period"2023年"profit"165010221.56"profit"202662270.20"profit"244060018.62"profit"-7834747.02"beginAsset"2761772535.39"beginAsset"2885521135.42"beginAsset"3312422711.80"beginAsset"3560111655.87"endAsset"2885521135.42"endAsset"3312422711.80"endAsset"3560111655.87"endAsset"3429031128.43cSoftList[1]cSoftList[0]cSoftListcSoftList[3]cSoftList[2]keyvaluekeyvaluekeyvaluekeyvaluecSoftList[0]cSoftList[1]cSoftList[2]cSoftList[3]使用循環(huán)提取2023年度的財報數(shù)據(jù)程序流程圖cSoftList[0]cSoftList[1]cSoftList[2]cSoftList[3]計算每年的凈資產(chǎn)收益率"period"2020年"period"2021年"period"2022年"period"2023年"profit"165010221.56"profit"202662270.20"profit"244060018.62"profit"-7834747.02"beginAsset"2761772535.39"beginAsset"2885521135.42"beginAsset"3312422711.80"beginAsset"3560111655.87"endAsset"2885521135.42"endAsset"3312422711.80"endAsset"3560111655.87"endAsset"3429031128.43cSoftList[1]cSoftList[0]cSoftListcSoftList[3]cSoftList[2]keyvaluekeyvaluekeyvaluekeyvalue

計算2023年的凈資產(chǎn)收益率cSoftList[0]cSoftList[1]cSoftList[2]cSoftList[3]

計算公式:"period"2023年"profit"-7834747.02"beginAsset"3560111655.87"endAsset"3429031128.43cSoftList[3]keyvalue計算每年的凈資產(chǎn)收益率"period"2020年"period"2021年"period"2022年"period"2023年"profit"165010221.56"profit"202662270.20"profit"244060018.62"profit"-7834747.02"beginAsset"2761772535.39"beginAsset"2885521135.42"beginAsset"3312422711.80"beginAsset"3560111655.87"endAsset"2885521135.42"endAsset"3312422711.80"endAsset"3560111655.87"endAsset"3429031128.43cSoftList[1]cSoftList[0]cSoftListcSoftList[3]cSoftList[2]keyvaluekeyvaluekeyvaluekeyvalue“ROE”0.0584386898“ROE”0.0653966138“ROE”0.0710247503“ROE”-0.002241977cSoftList[0]cSoftList[1]cSoftList[2]cSoftList[3]計算每年的凈資產(chǎn)收益率"period"2020年"period"2021年"period"2022年"period"2023年"profit"165010221.56"profit"202662270.20"profit"244060018.62"profit"-7834747.02"beginAsset"2761772535.39"beginAsset"2885521135.42"beginAsset"3312422711.80"beginAsset"3560111655.87"endAsset"2885521135.42"endAsset"3312422711.80"endAsset"3560111655.87"endAsset"3429031128.43“ROE”0.0584386898“ROE”0.0653966138“ROE”0.0710247503“ROE”-0.002241977cSoftList[1]cSoftList[0]cSoftListcSoftList[3]cSoftList[2]keyvaluekeyvaluekeyvaluekeyvalue更新后的cSoftList任務三使用for循環(huán)比較凈資產(chǎn)收益率的大小相關知識continue語句break語句continue語句在未執(zhí)行完當前循環(huán)的情況下,提前結束本次循環(huán),轉(zhuǎn)去進行下一次新的循環(huán)continuerange(4):迭代對象range(0,4)list(range(4))[0,1,2,3]break語句結束當前循環(huán),然后跳轉(zhuǎn)到循環(huán)后的下一條語句繼續(xù)執(zhí)行break輸出凈資產(chǎn)收益率超過5%的年度"period"2020年"period"2021年"period"2022年"period"2023年"profit"165010221.56"profit"202662270.20"profit"244060018.62"profit"-7834747.02"beginAsset"2761772535.39"beginAsset"2885521135.42"beginAsset"3312422711.80"beginAsset"3560111655.87"endAsset"2885521135.42"endAsset"3312422711.80"endAsset"3560111655.87"endAsset"3429031128.43“ROE”0.0584386898“ROE”0.0653966138“ROE”0.0710247503“ROE”-0.002241977cSoftList[1]cSoftList[0]cSoftListcSoftList[3]cSoftList[2]keyvaluekeyvaluekeyvaluekeyvaluecSoftList[0][“ROE”]>=0.05cSoftList[1][“ROE”]>=0.05cSoftList[2][“ROE”]>=0.05cSoftList[3][“ROE”]>=0.05使用continue控制for循環(huán)"period"2020年"period"2021年"period"2022年"period"2023年"profit"165010221.56"profit"202662270.20"profit"244060018.62"profit"-7834747.02"beginAsset"2761772535.39"beginAsset"2885521135.42"beginAsset"3312422711.80"beginAsset"3560111655.87"endAsset"2885521135.42"endAsset"3312422711.80"endAsset"3560111655.87"endAsset"3429031128.43“ROE”0.0584386898“ROE”0.0653966138“ROE”0.0710247503“ROE”-0.002241977cSoftList[1]cSoftList[0]cSoftListcSoftList[3]cSoftList[2]keyvaluekeyvaluekeyvaluekeyvaluecSoftList[0][“ROE”]<0.05cSoftList[1][“ROE”]<0.05cSoftList[2][“ROE”]<0.05cSoftList[3][“ROE”]<0.05使用continue控制for循環(huán)程序流程圖輸出第一個凈資產(chǎn)收益率超過5%的年度及凈資產(chǎn)收益率"period"2020年"period"2021年"period"2022年"period"2023年"profit"165010221.56"profit"202662270.20"profit"244060018.62"profit"-7834747.02"beginAsset"2761772535.39"beginAsset"2885521135.42"beginAsset"3312422711.80"beginAsset"3560111655.87"endAsset"2885521135.42"endAsset"3312422711.80"endAsset"3560111655.87"endAsset"3429031128.43“ROE”0.0584386898“ROE”0.0653966138“ROE”0.0710247503“ROE”-0.002241977cSoftList[1]cSoftList[0]cSoftListcSoftList[3]cSoftList[2]keyvaluekeyvaluekeyvaluekeyvaluecSoftList[0][“ROE”]>=0.05cSoftList[1][“ROE”]>=0.05cSoftList[2][“ROE”]>=0.05cSoftList[3][“ROE”]>=0.05輸出第一個凈資產(chǎn)收益率超過5%的年度及凈資產(chǎn)收益率程序流程圖任務四使用while循環(huán)比較相鄰年度凈資產(chǎn)收益率的變化相關知識while循環(huán)while循環(huán)的注意事項while循環(huán)控制語句塊的重復執(zhí)行條件為真時執(zhí)行語句塊

語句塊執(zhí)行結束再去判斷while條件

直到條件表達式值為假時結束循環(huán)while

條件表達式:

語句塊循環(huán)的控制結構,控制循環(huán)是否運行循環(huán)體此處為縮進,縮進量通常為4個字符條件表達式的值:真值或假值while循環(huán)示例cSoftList1[0]2020年cSoftList1[1]165010221.56cSoftList1[2]2761772535.39cSoftList1[3]2885521135.42cSoftList1循環(huán)條件判斷次數(shù)i值循環(huán)條件是否運行循環(huán)print(cSoftList1[i])i=i+1100<4為真是cSoftList1[0]i=1211<4為真是cSoftList1[1]i=2322<4為真是cSoftList1[2]i=3433<4為真是cSoftList1[3]i=4544<4為假否

比較相鄰年度凈資產(chǎn)收益率的變化"period"2020年"period"2021年"period"2022年"period"2023年"profit"165010221.56"profit"202662270.20"profit"244060018.62"profit"-7834747.02"beginAsset"2761772535.39"beginAsset"2885521135.42"beginAsset"3312422711.80"beginAsset"3560111655.87"endAsset"2885521135.42"endAsset"3312422711.80"endAsset"3560111655.87"endAsset"3429031128.43“ROE”0.0584386898“ROE”0.0653966138“ROE”0.0710247503“ROE”-0.002241977cSoftList[1]cSoftList[0]cSoftListcSoftList[3]cSoftList[2]keyvaluekeyvaluekeyvaluekeyvalueprePeriod=cSoftList[0]["period"]preROE=cSoftList[0]["ROE"]period=cSoftList[1]["period"]roe=cSoftList[1]["ROE"]prePeriod=cSoftList[1]["period"]preROE=cSoftList[1]["ROE"]period=cSoftList[2]["period"]roe=cSoftList[2]["ROE"]prePeriod=cSoftList[2]["period"]preROE=cSoftList[2]["ROE"]period=cSoftList[3]["period"]roe=cSoftList[3]["ROE"]比較相鄰年度凈資產(chǎn)收益率的變化"period"2020年"period"2021年"period"2022年"period"2023年"profit"165010221.56"profit"202662270.20"profit"244060018.62"profit"-7834747.02"beginAsset"2761772535.39"beginAsset"2885521135.42"beginAsset"3312422711.80"beginAsset"3560111655.87"endAsset"2885521135.42"endAsset"3312422711.80"endAsset"3560111655.87"endAsset"3429031128.43“ROE”0.0584386898“ROE”0.0653966138“ROE”0.0710247503“ROE”-0.002241977cSoftList[1]cSoftList[0]cSoftListcSoftList[3]cSoftList[2]keyvaluekeyvaluekeyvaluekeyvalue2020年2021年2021年比較相鄰年度凈資產(chǎn)收益率的變化

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論