python(三)——while语句
while死循环
#!/usr/bin/env python
#-*- coding:utf8 -*- import time
while 1 == 1:
print('Ok',time.time())
import time count = 0
while count < 10:
print('Ok',time.time())
count = count + 1 print('')
# 输出1-100内所有的偶数
count = 1
while count <= 100:
if count % 2 == 0:
print(count)
count = count + 1
# 求 1-2+3-4+5-6...99所有数的和
count = 1
sum = 0
while count < 100:
temp = count
if count % 2 == 0:
temp = -count
sum += temp
count = count + 1 print(sum)
# while 输出1 2 3 4 5 6 7 8 9 n = 0
while n < 10:
if n == 7:
pass
else:
print(n)
n = n + 1
#!/usr/bin/env python
#-*- coding:utf8 -*- # 允许用户登录三次
# 变量
count = 0
while count < 3:
n1 = input('请输入用户名:')
n2 = input('请输入用户名密码:') if n1 == 'root' and n2 == 'root123':
print('登录成功')
count = 3
else:
print('登录失败') count = count + 1
python(三)——while语句的更多相关文章
- 理解python的with语句
Python’s with statement provides a very convenient way of dealing with the situation where you have ...
- Python之with语句
Python之with语句 在Python中,我们在打开文件的时候,为了代码的健壮性,通常要考虑一些异常情况,比如: try: ccfile = open('/path/data') content ...
- 转: 理解Python的With语句
Python’s with statement provides a very convenient way of dealing with the situation where you have ...
- python的with语句,超级强大
With语句是什么? 有一些任务,可能事先需要设置,事后做清理工作.对于这种场景,Python的with语句提供了一种非常方便的处理方式.一个很好的例子是文件处理,你需要获取一个文件句柄,从文件中读取 ...
- 简单探讨python中的语句和语法
python程序结构 python"一切皆对象",这是接触python听到最多的总结了.在python中最基层的单位应该就是对象了,对象需要靠表达式建立处理,而表达式往往存在于语句 ...
- Python 中的语句
上一节已经了解到了Python中的基本数据类型和一些基本的操作,本节就大致讲一下关于Python中的语句的相关问题. 我们熟悉的print()语句可能是这样的.print('YJK923') or p ...
- Python学习-6.Python的分支语句
Python的分支语句比较简单,只有if.else.elif三个关键字,也就是说,Python没有switch语句,而且,Python中并没有?:这个三目运算符. 例子: age = 18 if ag ...
- Python 的条件语句和循环语句
一.顺序结构 顺序结构是最简单的一种程序结构,程序按照语句的书写次序自上而下顺序执行. 二.分支控制语句 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块 ...
- Python - 三大器 迭代器,生层器,装饰器
目录 Python - 三大器 迭代器,生层器,装饰器 一. 容器 二. 可迭代对象(iterable) 三. 迭代器 四. 生成器 五. 装饰器 1. 定义 六. 闭包 Python - 三大器 迭 ...
随机推荐
- PB 修改datawindow 的背景色
1.修改标题行的背景色 rgb(235, 235, 235) 2.修改选择行的背景色(即选择行高亮) if(currentrow() = getrow(), rgb(235,235,235), rgb ...
- Locust性能测试_参数关联
前言 前面[Locust性能测试2-先登录场景案例]讲了登录的案例,这种是直接传账号和密码就能登录了,有些登录的网站会复杂一点, 需要先从页面上动态获取参数,作为登录接口的请求参数,如[学信网:htt ...
- pytest_06_fixture之yield实现teardown
上一篇讲到fixture通过scope参数控制setup级别,既然有setup作为用例之前前的操作,用例执行完之后那肯定也有teardown操作. 这里用到fixture的teardown操作并不是独 ...
- MEF在WCF REST中实际应用2(Global.asax注册)
IOCContainer文件: public class IOCContainer { /// <summary> /// 容器 /// </summary> public s ...
- Spring-Cloud之Feign声明式调用-4
一.Feign受Retrofit.JAXRS-2.0和WebSocket影响,采用了声明式API 接口的风格,将Java Http 客户端绑定到它的内部. Feign 首要目的是将 Java Http ...
- Parameter 0 of method sqlSessionTemplate in org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration required a single bean, but 2 were found:
Parameter 0 of method orderSqlSessionFactory in com.config.MultipleDBConfig required a single bean, ...
- Java—十进制数对n进制数转换
import java.math.BigInteger;import java.util.Scanner; /** * @auther Aohui * @create 2019-11-06-15:33 ...
- 关于 Safari 浏览器不支持 location [ window.location.href window.open()] 跳转问题的解决方案
最近在做项目时,碰到 safari 浏览器不支持location跳转问题,针对此问题,可以通过 js 模拟点击时间来解决,代码如下: <!DOCTYPE HTML> <html la ...
- Oracle数据库之操作符及函数
一.操作符: 1.分类: 算术.比较.逻辑.集合.连接: 2.算术操作符: 执行数值计算: -- 工资加1000 from emp; 3.比较操作符: -- 比较运算符(between and包头不包 ...
- JavaWeb 之 Filter 验证用户登录案例
需求: 1. 访问一个网站的资源.验证其是否登录 2. 如果登录了,则直接放行. 3. 如果没有登录,则跳转到登录页面,提示"您尚未登录,请先登录". 代码实现: import j ...