练习33——while循环
来源:互联网 发布:murmurhash算法原理 编辑:程序博客网 时间:2024/04/29 06:40
# coding:utf-8# ex33 While 循环#while循环使用布尔值判断来决定是不是继续执行循环。可以实现比for更复杂的操作。#++++原练习代码++++i = 0numbers = []while i < 6: print "At the top i is %d" % i numbers.append(i) i = i + 1 print "Numbers now: ", numbers print "At the bottom i is %d" % iprint "The numbers: "for num in numbers: print num#+++++++++++++++#++++根据加分题改写后的代码++++i = 0numbers = []maxium = int(input("please input a number!\n"))step = int(input("please input a step!\n"))while i < maxium: print ("At the top i is %d" % i) numbers.append(i) i += step print ("Numbers now:", numbers) print ("At the bottom i is %d" % i)print ("The numbers:")for num in numbers: print (num)#++++++++++++++++++++++++++#加分题:# 1.将这个 while 循环改成一个函数,将测试条件(i < 6)中的 6 换成一个变量。# 定义一个变量,我这里用用户输入的数字作为变量的值。↓# maxium = int(input("please input a number!\n"))# 把6替换成变量↓# while i < maxium:# 2.使用这个函数重写你的脚本,并用不同的数字进行测试。# 3.为函数添加另外一个参数,这个参数用来定义第 8 行的加值 + 1 ,这样你就可以让它任意加值了。# 同样的方法我添加了一个step变量。# 4.再使用该函数重写一遍这个脚本。看看效果如何。# 5.接下来使用 for-loop 和 range 把这个脚本再写一遍。你还需要中间的加值操作吗?如果你不去掉它,会有什么样的结果?# for循环中可以使用in range(a,b,c) a->起始值,b->结束值,c->跨度(step)值,从而实现和本脚本一样的效果
0 0
- 练习33——while循环
- 练习33:while循环
- while循环和练习
- while循环练习
- while循环嵌套练习
- while循环嵌套练习
- while循环的中断练习
- java9——while循环
- 基础知识—循环语句-while
- 循环结构语句——while循环
- 猜数字游戏练习do-while循环
- java两层循环练习for,while
- java学习10--循环结构while练习
- JAVA 五 while循环结构练习
- 黑马程序员——while、do...while、for循环
- php中while和do—while循环语句
- Mohican_12/12 C语言—循环 for ,while,do while
- 循环语句For While do-while的小练习
- LinkedME|iOS移动应用开发者不得不知道的Deep Linking技术
- CCTYPE函数系列
- 代码笔记总结(一些别人写的代码)
- C语言简述
- Android 中的Messenger
- 练习33——while循环
- ServletConfig与ServletContext对象详解 转载
- Android 使用OpenCV的三种方式(Android Studio)
- sqlite实现概览
- stuts2 全局错误拦截配置
- UVA - 679 Dropping Balls 二叉树找规律
- HDU 1518 Square
- Qt学习之路(34): 国际化(下)
- 网络数据强制数据转化