#使用while循环输出1 2 3 4 5 6 8 9 10 (方法1)
1 count = 1
2 while count < 11:
3 print(count)
4 count = count + 1
5 if count == 7:
6 count = count + 1
7 print("----end----")
#使用while循环输出1 2 3 4 5 6 8 9 10 (方法2)
1 count = 1
2 while count < 11:
3 if count == 7:
4 pass
5 else:
6 print(count)
7 count = count + 1
8
9 print("----end----")
#输出1-100 内的所有奇数
1 count = 1
2 while count < 101:
3 if count % 2 != 0:
4 print(count)
5 count = count +1
#输出1-100 内的所有偶数
1 count = 1
2 while count < 101:
3 if count % 2 == 0:
4 print(count)
5 count = count +1
#求1-100的所有数的和
1 count = 1
2 a = 0
3 while count < 101:
4 a = a + count
5 count = count +1
6 print(a)
#求1-2+3-4+5 ... 99的所有数的和(方法1)
1 count = 1
2 a = 0
3 b = 0
4 while count < 100:
5 if count % 2 != 0:
6 a = count + a
7 count = count + 1
8 else:
9 b = b -count
10 count = count + 1
11 print(a+b)
#求1-2+3-4+5 ... 99的所有数的和(方法2)
1 count = 1
2 a = 0
3 while count < 100:
4 temp = count % 2
5 if temp == 0:
6 a = a - count
7 else:
8 a = a + count
9 count = count + 1
10
11 print(a)
#用户登录(三次机会)
1 user_id = "zxf"
2 pass_word = "123"
3 count = 3
4 name = input("请输入账号:")
5 mima = input("请输入密码:")
6 while count > 1:
7 count = count -1
8 if name == user_id and mima == pass_word:
9 print("欢迎登录")
10 count = 0
11 elif name != user_id or mima != pass_word and count > 2:
12 print("账号或密码不正确请重试")
13 name = input("请输入账号:")
14 mima = input("请输入密码:")
15 if count == 1:
16 print("错误多次无法登录。")