版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
项目五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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- T/CSES 217-2025水质 12种抗生素抗性基因和1种可移动遗传元件的测定 实时荧光定量PCR法
- T/UNP 89-2024建筑工程施工现场安全生产管理规范
- T/GZCBD 009-2024“贵系列”品牌 银饰类评分规范
- T/CI 959-2025储氢用钒合金
- T/CAIEC 088-2025全装修住宅施工管理与质量验收规范
- T/CSAE 380-2024汽车双倍数据速率同步动态随机存储器工作寿命试验方法
- 2025~2026学年江苏省宿迁市宿豫区多校苏教版六年级上册月考数学试卷【附答案】
- AI在阿非利卡语中的应用
- 2025-2026学年湖北省荆州市初中数学八年级期末下册点睛提升潜能激发题详细参考解析
- 2027届贵州省六盘水市第二十中学数学七年级第一学期期末考试试题含解析
- 2026军队文职招聘-军队文职技能岗-军队文职招聘(炊事员-食堂管理员)历年参考题库含答案详解
- 山东齐鲁名校教育测评2026年10月高三年级学业质量检测地理+答案
- 2.4 光的反射现象 课件(内嵌视频)2026-2027学年科学六年级上册教科版
- 2026年6月浙江高考选考技术试卷真题(含答案详解)
- 部编版五年级上册语文第七单元《习作:我最喜爱的季节》教学课件(新教材)
- 2026中国建设银行招聘考试(英语)历年参考题库含答案详解
- (2026年)清廉学校建设年度工作总结
- 2026年机电工程中级职称考试《专业基础知识》考试题库及答案
- 2026年江苏省中学生生物学奥林匹克初赛理论试题解析
- 脾胃科药物知识及使用宣教
- 人教版九年级全册英语专题复习教案全集
评论
0/150
提交评论