python(三)——while语句

while死循环

1 #!/usr/bin/env python
2 #-*- coding:utf8 -*-
3 
4 import time
5 while 1 == 1:
6     print('Ok',time.time())
import time

count = 0
while count < 10:
    print('Ok',time.time())
    count = count + 1
    
print('123')
# 输出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

猜你喜欢

转载自www.cnblogs.com/xiangtingshen/p/10344377.html