摘要: for循环 像while循环一样,for可以完成循环的功能。 在Python中 for循环可以遍历任何序列的项目,如一个列表或者一个字符串等。 for循环的格式 for 临时变量 in 列表或者字符串等可迭代对象: 循环满足条件时执行的代码 demo1 name = 'itheima' for x 阅读全文
posted @ 2020-04-10 21:43 kelin1 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 1. 计算1~100的累积和(包含1和100) 参考代码如下: #encoding=utf-8 i = 1 sum = 0 while i <= 100: sum = sum + i i += 1 print("1~100的累积和为:%d" % sum) 或者 # 1. 计算1~100的累积和(包含 阅读全文
posted @ 2020-04-10 21:36 kelin1 阅读(225) 评论(0) 推荐(0) 编辑