1. 使用while 输出 1 2 3 4 5 6 8 9 10。
#!/usr/bin/env python

num = 1
while num <= 10:
    if num != 7:
        print(num)
    num+=1
  1. 输出1-100内所有数的和 。
#!/usr/bin/env python

sum = 0
num = 1
while num <= 100:
    sum = sum + num
    num = num + 1
print(sum)
  1. 输出1-100所有的奇数
#!/usr/bin/env python

num = 1
while num <= 100:
    if num % 2 != 0:
        print(num)
    num =num + 1
  1. 输出1-100所有的偶数
#!/usr/bin/env python

num = 1
while num <= 100:
    if num % 2 == 0:
        print(num)
    num =num + 1

5.计算1-2+3=4+5.....99的和。

#!/usr/bin/env python

num = 1
sum1 = 0
sum2 = 0
while num < 100:
    temp = num % 2
    if temp != 0:
        sum1 += num
    else:
        sum2 += num
    num += 1

print(sum1-sum2)

6.用户登陆(三次重试机会)

#!/usr/bin/env python

count = 0
while count < 4:
    user = input("请输入用户名:")
    pwd = input("请输入密码:")

    if user == 'root'  and pwd == 'root':
        print("登陆成功!")
    else:
        print("用户名或密码错误,请重新输入!")
        count += 1

print("超过重试次数限制,登陆失败!")