一个程序学会python的流程控制
2016-07-11 09:20
781 查看
song@ubuntu:~$ vi ex4.py
song@ubuntu:~$ more ex4.py
#!/usr/bin/env python
#_*_ coding:utf-8 _*_
print_num=input('Which loop do you want to be printed out?:')
count=0
while count<30:
if count==print_num:
print 'There you have got the number:',count
choice=raw_input('Do you want to continue the loop?(y/n):')
if choice=='n':
print 'The while loop is broken by break!'
break
else:
print_num=input('Which loop do you want to be printed out?:')
while print_num<=count:
print '%d has gone,please enter another number!' % print_num
print_num=input('Which loop do you want to be printed out?:')
else:
print 'Loop:',count
count+=1
else:
print 'The while loop is over normally!'
song@ubuntu:~$
song@ubuntu:~$ python ex4.py
Which loop do you want to be printed out?:3
Loop: 0
Loop: 1
Loop: 2
There you have got the number: 3
Do you want to continue the loop?(y/n):n
The while loop is broken by break!
song@ubuntu:~$
song@ubuntu:~$ python ex4.py
Which loop do you want to be printed out?:19
Loop: 0
Loop: 1
Loop: 2
Loop: 3
Loop: 4
Loop: 5
Loop: 6
Loop: 7
Loop: 8
Loop: 9
Loop: 10
Loop: 11
Loop: 12
Loop: 13
Loop: 14
Loop: 15
Loop: 16
Loop: 17
Loop: 18
There you have got the number: 19
Do you want to continue the loop?(y/n):y
Which loop do you want to be printed out?:16
16 has gone,please enter another number!
Which loop do you want to be printed out?:19
19 has gone,please enter another number!
Which loop do you want to be printed out?:28
Loop: 20
Loop: 21
Loop: 22
Loop: 23
Loop: 24
Loop: 25
Loop: 26
Loop: 27
There you have got the number: 28
Do you want to continue the loop?(y/n):y
Which loop do you want to be printed out?:30
Loop: 29
The while loop is over normally!
song@ubuntu:~$
song@ubuntu:~$ more ex4.py
#!/usr/bin/env python
#_*_ coding:utf-8 _*_
print_num=input('Which loop do you want to be printed out?:')
count=0
while count<30:
if count==print_num:
print 'There you have got the number:',count
choice=raw_input('Do you want to continue the loop?(y/n):')
if choice=='n':
print 'The while loop is broken by break!'
break
else:
print_num=input('Which loop do you want to be printed out?:')
while print_num<=count:
print '%d has gone,please enter another number!' % print_num
print_num=input('Which loop do you want to be printed out?:')
else:
print 'Loop:',count
count+=1
else:
print 'The while loop is over normally!'
song@ubuntu:~$
song@ubuntu:~$ python ex4.py
Which loop do you want to be printed out?:3
Loop: 0
Loop: 1
Loop: 2
There you have got the number: 3
Do you want to continue the loop?(y/n):n
The while loop is broken by break!
song@ubuntu:~$
song@ubuntu:~$ python ex4.py
Which loop do you want to be printed out?:19
Loop: 0
Loop: 1
Loop: 2
Loop: 3
Loop: 4
Loop: 5
Loop: 6
Loop: 7
Loop: 8
Loop: 9
Loop: 10
Loop: 11
Loop: 12
Loop: 13
Loop: 14
Loop: 15
Loop: 16
Loop: 17
Loop: 18
There you have got the number: 19
Do you want to continue the loop?(y/n):y
Which loop do you want to be printed out?:16
16 has gone,please enter another number!
Which loop do you want to be printed out?:19
19 has gone,please enter another number!
Which loop do you want to be printed out?:28
Loop: 20
Loop: 21
Loop: 22
Loop: 23
Loop: 24
Loop: 25
Loop: 26
Loop: 27
There you have got the number: 28
Do you want to continue the loop?(y/n):y
Which loop do you want to be printed out?:30
Loop: 29
The while loop is over normally!
song@ubuntu:~$
相关文章推荐
- mac 安装robotFramwork环境 以及wxPython 无法安装问题解决 (非常有用)
- Python collections模块实例讲解
- Python编写简单的HTML页面合并脚本
- Python中super()函数简介及用法分享
- python关于列表转为字典的两个小方法
- python常用代码片
- Python中super()函数简介及用法分享
- Python编写简单的HTML页面合并脚本
- Python中的异常处理相关语句基础学习笔记
- Python的SQLalchemy模块连接与操作MySQL的基础示例
- Python的requests网络编程包使用教程
- Windows中使用wxPython和py2exe开发Python的GUI程序的实例教程
- 使用Python的Tornado框架实现一个Web端图书展示页面
- 深入解析Python的Tornado框架中内置的模板引擎
- 浅析Python的web.py框架中url的设定方法
- Python - 数据库(pyMongo)
- 一句Python命令启动一个Web服务器
- 《机器学习》周志华习题4.4答案
- NumPy基本方法
- python学习日记——1