python第五篇-while
来源:互联网 发布:mac上编程软件 编辑:程序博客网 时间:2024/06/14 02:26
#!/usr/bin/python#fileName:while.pynumber = 23running = Truewhile running: guess=int(input("enter an integer:")) if guess==number: print("Congratulatio,you guess it") running=False elif guess>number: print("no,it is a little higher.") else: print("no,it is a little lower")else: print("the while is over")print("done")
结果:
kwang@ubuntu:a_byte_python->./while.py enter an integer:4no,it is a little lowerenter an integer:3no,it is a little lowerenter an integer:43no,it is a little higher.enter an integer:23Congratulatio,you guess itthe while is overdone这里首先定义俩两个变量,number和running,其中number是整型变量,running是布尔变量(也是0和1)。之后程序使用俩while和if语句的嵌套,分为三部分,其中第一个if语句为第一部分,代表判断用户输入的值为number的值,第二部分就是elif部分,判断用户输入的值大于number的值,之后就是elif下面的else语句,用户判断用户输入的值小于number,最后一个else和while并列,表示while条件不成立时运行。其中还是要注意:在python中对于不同部分的区分时语句开头的tab键,使的语句对齐方式不一样,从而代表不同的部分。
阅读全文
0 0
- python第五篇-while
- python基础第五篇
- 新手学python 第五篇 Python基础
- Python基础篇之while循环
- 我的Python第五篇 函数篇
- 我的Python第五篇 面向对象
- 第五 Java循环结构之while循环
- Python的while循环
- python if while用法
- python的while语句
- python while else
- while-loop in python
- Python While循环语句
- python while循环控制
- python中的while循环
- python的while语法
- python while循环
- 3.2 Python while语句
- [Algorithm]九章八:Data Structure
- [Algorithm] Palindrome 问题
- VC编译调试比特币源码
- 自定义View环形递增
- 根据字符串格式的模型路径获得模型
- python第五篇-while
- PB9阿里大于发短信
- java面试题1
- PB9网易云信发短信
- OC语法详解
- 牛客day3
- 圈点生活......
- Linux crontab
- Servlet的基本架构