博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
一个程序学会python的流程控制
阅读量:4171 次
发布时间:2019-05-26

本文共 1681 字,大约阅读时间需要 5 分钟。

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:~$ 

转载地址:http://scyai.baihongyu.com/

你可能感兴趣的文章
商务智能-系统概述-数据图形方式
查看>>
软件项目管理系统-项目管理-模块定义-开发内容
查看>>
工作流审批平台-审批功能
查看>>
商务智能-基本方法-特征与角度
查看>>
软件项目管理系统-项目管理-模块定义-开发笔记
查看>>
工作流审批平台-业务申请-申请书一览
查看>>
商务智能-基本方法-数据钻取
查看>>
C++程序员技术需求规划(发展方向)
查看>>
2018.12.5
查看>>
2018.12.6
查看>>
人智导(四):约束满足问题
查看>>
2018.12.7
查看>>
2018.12.8
查看>>
2018.12.9
查看>>
2018.12.29
查看>>
2018.12.31
查看>>
2019.1.2
查看>>
2019.1.4
查看>>
2019.1.9
查看>>
2019.1.12
查看>>