1、使用while输入1 2 3 4 5 6 8 9 10
1 count = 1
2 while count < 11:
3 if count != 7:
4 print(count)
5 count = count + 1
1 count = 1
2 while count < 11:
3 if count == 7:
4 count = count + 1
5 continue
6 print(count)
7 count = count + 1
2、求1-100所有数 的和
1 i = 0
2 sum = 0
3 while i < 101:
4 sum = sum + i
5 i = i + 1
6 print(i)
7 print(sum)
8 print(sum)
3、输出1-100内的所有奇数、偶数
1 i = 1
2 while i < 101:
3 if i % 2 == 0:
4 print(i)
5 i = i + 1
4、求1-2+3—4+5...99所有数的和
1 i = 1
2 sum1 = 0
3 sum2 = 0
4 while i < 100:
5 if i % 2 == 0:
6 sum1 = sum1 -i
7 else:
8 sum2 = sum2 + i
9 i = i + 1
10 print(sum1 + sum2)
1 i = 0
2 s = 0
3 while i < 100:
4 temp = i % 2
5 if temp == 0:
6 s = s - i
7 else:
8 s = s + i
9 i = i + 1
10 print(s)
5、用户登录(三次重试机会)
1 i = 1
2 while i < 4:
3 name = input('请输入用户名:')
4 password = input('请输入密码:')
5 if name == 'root' and password == 'root':
6 print('登录成功')
7 break
8 elif i < 3:
9 print('请重试')
10 elif i == 3:
11 print("稍后重试")
12 i = i + 1