摘要: #冒泡排序 lista=[5,8,9,11,2,3,1,4] count=0 for x in range(1,len(lista)-1+1) print(x) for y in range(0,len(lista)-x-1+1) print(y,y+1) #升序 if lista[y]>=list 阅读全文
posted @ 2022-07-28 15:45 测试小潘 阅读(29) 评论(0) 推荐(0)
摘要: #嵌套循环案例 for year in range(1,11): print("第",year,"年到了") for x in year range(1,3): print("第",x,"月到了") #遍历多维容器 例: lisata=[1,11,12,131,141] lisatb=[1,11,1 阅读全文
posted @ 2022-07-28 15:27 测试小潘 阅读(112) 评论(0) 推荐(0)
摘要: while 循环 表示通过判断条件来控制循环语句的执行 while 判断条件 执行语句 确定循环条件而不确定循环次数时使用 for循环适合循环次数确定的业务,可以直接遍历容器 while适合已知循环条件的业务 i=1 while i<=10: print("hello") i=i+1 阅读全文
posted @ 2022-07-28 15:16 测试小潘 阅读(48) 评论(0) 推荐(0)
摘要: scores=[67,38,65,98,78,54] max(scores) min(scores) masScores=scores[0] forScore in scores: if Score>masScore: maxScore=score #将更大值变更为最大值 print(maxScor 阅读全文
posted @ 2022-07-28 15:01 测试小潘 阅读(82) 评论(0) 推荐(0)
摘要: 循环结构 for 循环 for x in range(1,10): print("hellow") for循环 #遍历容器 #将容器或序列中的数据一个一个取出来 for x in 列表名: print() #直接遍历 names = ["张三","李四","王五","李留","王二麻子"] for 阅读全文
posted @ 2022-07-28 14:08 测试小潘 阅读(28) 评论(0) 推荐(0)
摘要: 小数转换二进制时无法精确去转换 round()函数时用来保留制定的小数位 a=15.3 b=3 c=a/b print(round(c,2)) 阅读全文
posted @ 2022-07-28 13:25 测试小潘 阅读(83) 评论(0) 推荐(0)