1、使用while循环输入 1 2 3 4 5 6 8 9 10i = 0
while i
i += 1
if i == 7:
continue
else:
print(i)
2、求1-100的所有数的和i = 0
sum = 0
while i
i += 1
sum = sum + i
print(sum)
3、输出 1-100 内的所有奇数i = 0
while i
i += 1
if i%2 == 1:
print(i)
else:
continue
4、输出 1-100 内的所有偶数i = 0
while i
i += 1
if i%2 == 0:
print(i)
else:
continue
5、求1-2+3-4+5 ... 99的所有数的和i = 1
sum = 0
while i
if i%2 == 1 :
sum += i
else:
sum -= i
i += 1
print(sum)
6、用户登陆(三次机会重试)i = 0
while i
username = input('请输入您的用户名:')
password = input('请输入您的密码:')
i += 1
if username == 'oldboy' and password == '123':
print('恭喜您,输入正确!')
break
else:
print('输入错误,请重新输入')
continue