
正文
python(三)——while语句
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
while死循环
#!/usr/bin/env python
#-*- coding:utf8 -*- import time
while 1 == 1:
print('Ok',time.time())
import timecount = 0
while count < 10:
print('Ok',time.time())
count = count + 1print('')
# 输出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 + 1print(sum)
# while 输出1 2 3 4 5 6 7 8 9n = 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







