习题33 while循环
来源:互联网 发布:蜂窝网络和移动网络 编辑:程序博客网 时间:2024/04/29 06:45
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
这个程序并不难,需要知道的就是第一块里面的 append(i) 是为了给 numbers 加数字用的
第二节的 for 更不用说了,就是输出 numbers 里面的数字而已
运行结果如下:
=====================================================================================
附加练习:
1-4 参考
i = 0print "Input a for 'while i < a': "a = int(raw_input("> "))print "Input b for 'i = i + b': "b = int(raw_input("> "))numbers = []while i < a: print "At the top i is %d" % i numbers.append(i) i = i + b print "Numbers now: ", numbers print "At the bottom i is %d" % iprint "The numbers: "for num in numbers: print num
运行结果
5.
i = 0print "Input a for 'i in range(0,a)': "a = int(raw_input("> "))#print "Input b for 'i = i + b': "#b = int(raw_input("> "))numbers = []for i in range(0,a): print "At the top i is %d" % i numbers.append(i) # i = i + b print "Numbers now: ", numbers print "At the bottom i is %d" % iprint "The numbers: "for num in numbers: print num
运行结果:
现在试一试去掉注释中的 i = i + b
结果就不贴了,好像没什么区别
0 0
- 习题33 while循环
- 笨方法学python 习题32(循环和列表)习题33(while循环)
- while循环,习题33,笨办法学python
- 笨方法学Python 习题 33: While 循环
- 笨方法学习Python-习题33: While 循环
- c++primer 6.15while循环习题!
- while循环和for循环的比较,习题33,笨方法学python
- Exercise 33: While 循环
- 练习33:while循环
- exercise 33 while循环
- while循环
- while循环
- while循环
- while循环
- while循环
- While循环
- while循环
- while 循环
- 画一个三角形
- 手机上传图片
- activeMq的发布订阅模式
- 人工差错处理的过程
- NYOJ 1058部分和问题(DFS)
- 习题33 while循环
- 注解实现Bean依赖注入
- ADB命令行的常用指令
- c++ map set综合运用
- socket编程之pthread多线程通信
- xmos控制一组GPIO
- java 邮件发送详细版
- 几个推荐的android studio插件
- NanoPC-T2 Uboot启动过程分析- 1 上电启动