一个程序学会python的流程控制
来源:互联网 发布:山东黄金历史交易数据 编辑:程序博客网 时间:2024/06/13 23:19
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:~$
1 0
- 一个程序学会python的流程控制
- Python程序流程控制
- 程序的流程控制
- Python的流程控制
- 什么是流程控制,如何看懂一个程序
- 五 程序的流程控制
- 2.5程序的流程控制
- 程序里面的流程控制
- 模拟一个银行转账流程的Python小程序
- 六、Python的程序流程
- **PYTHON** 程序的控制结构
- shell学习之-程序的流程控制
- 6.C++ 程序的流程控制
- 笔记03 程序的流程控制
- php程序的三大流程控制
- 流程控制的基本程序题目库
- JAVA基础:程序的流程控制知识点
- R语言之程序的流程控制
- Golang Web编程的Get和Post请求发送与解析
- 多重背包二进制优化模板分析
- 责任链模式
- 深入理解Java虚拟机--垃圾回收算法
- XML_JSON
- 一个程序学会python的流程控制
- php之字符串
- Android进程管理之taskinfo模型
- 一个很赞的RecyclerView Adapter辅助类
- 响应式网页必备——media媒体查询
- 实现一个简易的IoC框架(上)(此篇与Spring.NET无关,为自己手写IoC框架)
- 《剑指offer》-左旋转字符串
- 关于Oracle Sales Cloud中产品组模板下载与数据导入的配置
- /ufeff,php解决方案