




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
项目五Python循环结构程序设计目标理解循环结构理解for循环和while循环的用法了解continue和break的用法任务一存储2020年到2023年的相关财报数据相关知识各年数据的存储全部数据的存储年
度2020年2021年2022年2023年净利润165010221.56202662270.20244060018.62-7834747.02期初净资产2761772535.392885521135.423312422711.803560111655.87期末净资产2885521135.423312422711.803560111655.873429031128.43各年数据的存储每年数据如何存储?年
度2020年2021年2022年2023年净利润165010221.56202662270.20244060018.62-7834747.02期初净资产2761772535.392885521135.423312422711.803560111655.87期末净资产2885521135.423312422711.803560111655.873429031128.43各年数据的存储每年数据如何存储?年
度2020年净利润165010221.56期初净资产2761772535.39期末净资产2885521135.42各年数据的存储每年数据存入一个字典年
度2020年2021年2022年2023年净利润165010221.56202662270.20244060018.62-7834747.02期初净资产2761772535.392885521135.423312422711.803560111655.87期末净资产2885521135.423312422711.803560111655.873429031128.43cSoftDict1cSoftDict2cSoftDict3cSoftDict4["profit"]["beginAsset"]["endAsset"]["period"]各年数据的存储每年数据存入一个字典
全部数据的存储用一个列表存储四个字典任务二使用for循环计算各年净资产收益率相关知识for循环range函数for循环控制语句块的重复执行for和in都是关键字迭代器是Python语言中的重要机制之一for循环变量in迭代器:
语句块
循环的控制结构,它控制for中语句块的执行次数循环体此处为缩进,缩进量通常为4个字符迭代器是一个值序列,或值集合迭代器中的值的个数就是for循环的次数for循环循环次数i值循环体10i的值为021i的值为132i的值为243i的值为3示例for循环循环次数i值循环体110i=10213i=13316i=16417i=17示例for循环循环次数item值循环体1’a’item=a2’b’item=b3’abc’item=abc4100item=100示例range()函数产生指定范围的一系列值常作为for循环的迭代器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循环示例一cSoftList1[3]cSoftList1[2]cSoftList1[1]年
度2020年净利润165010221.56期初净资产2761772535.39期末净资产2885521135.42cSoftList1[0]cSoftList10,1,2,32,31,3for循环示例二["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使用循环从列表cSoftList中提取数据"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使用循环从列表cSoftList中提取数据程序流程图使用循环从列表cSoftList中提取数据"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使用循环从列表cSoftList中提取年度数据"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]使用循环提取2023年度的财报数据"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]使用循环提取2023年度的财报数据程序流程图cSoftList[0]cSoftList[1]cSoftList[2]cSoftList[3]计算每年的净资产收益率"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年的净资产收益率cSoftList[0]cSoftList[1]cSoftList[2]cSoftList[3]
计算公式:"period"2023年"profit"-7834747.02"beginAsset"3560111655.87"endAsset"3429031128.43cSoftList[3]keyvalue计算每年的净资产收益率"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]计算每年的净资产收益率"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循环比较净资产收益率的大小相关知识continue语句break语句continue语句在未执行完当前循环的情况下,提前结束本次循环,转去进行下一次新的循环continuerange(4):迭代对象range(0,4)list(range(4))[0,1,2,3]break语句结束当前循环,然后跳转到循环后的下一条语句继续执行break输出净资产收益率超过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循环"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循环程序流程图输出第一个净资产收益率超过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输出第一个净资产收益率超过5%的年度及净资产收益率程序流程图任务四使用while循环比较相邻年度净资产收益率的变化相关知识while循环while循环的注意事项while循环控制语句块的重复执行条件为真时执行语句块
语句块执行结束再去判断while条件
直到条件表达式值为假时结束循环while
条件表达式:
语句块循环的控制结构,控制循环是否运行循环体此处为缩进,缩进量通常为4个字符条件表达式的值:真值或假值while循环示例cSoftList1[0]2020年cSoftList1[1]165010221.56cSoftList1[2]2761772535.39cSoftList1[3]2885521135.42cSoftList1循环条件判断次数i值循环条件是否运行循环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为假否
比较相邻年度净资产收益率的变化"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"]比较相邻年度净资产收益率的变化"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年比较相邻年度净资产收益率的变化
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 施工阶段资金管理制度范本
- 2腊八粥(教学设计)-2023-2024学年语文六年级下册统编版
- 《6 飞翔的风筝》(教学设计)-2023-2024学年五年级下册综合实践活动皖教版
- 18古诗三首《书湖阴先生壁》教学设计2024-2025学年统编版语文六年级上册
- 2025年中国信封印刷行业市场发展前景及发展趋势与投资战略研究报告
- 21古诗三首 教学设计-2024-2025学年语文四年级上册统编版
- 2025年隔挡机项目投资可行性研究分析报告
- 通过户外混龄体育活动促进幼儿健康成长
- CHC燃料油项目可行性研究报告
- 2025年铁路敞车项目可行性研究报告
- 2024阿里巴巴云计算云主机租赁及运维服务合同2篇
- 消毒供应中心礼仪培训
- 微信公众号运营步骤
- 《软件开发质量管理研究的国内外文献综述》7100字
- 健康体检结果分析与健康干预策略
- 碳中和技术概论 课件 第1-3章 碳中和概述、太阳能、风能
- 初中数学新课程标准(2024年版)
- 育婴员初级培训
- 新能源汽车三电系统培训教材
- DB43T 578-2016 锑冶炼砷碱渣无害化处理技术规范
- 建筑与市政工程地下水控制技术规范 JGJ111-2016 培训
评论
0/150
提交评论