一、使用while循环输入 1 2 3 4 5 6 _ 7 8 9 1
count = 1
while count < 11:
if count == 7:
print(' ')
else:
print(count)
count += 1
二、求1-100所以自然数之和
1 x = 1
2 s = 0
3 while x < 101:
4 s = s + x
5 x += 1
6 print(s)
三、输出1-100所以奇数
count = 1
while count < 101:
if count % 2 == 1:
print(count)
count += 1
四、输出1-100所以偶数
count = 1
while count < 101:
if count % 2 == 0:
print(count)
count += 1
五、求1-2+3-4+5...99的结果
count = 1
s = 0
while count < 100:
if count % 2 == 1:
s = s + count
else:
s = s - count
count += 1
print(s)
六、用户登录(三次机会重试)
i = 0
while i < 3:
username = input('请输入账号:')
password = int(input('请输入密码:'))
if username == '我爱你' and password == 123:
print('登陆成功')
else:
print('登录失败,请重新输入账号密码')
i += 1