1.利用while输出1 2 3 4 5 6 8 9 10
i = 1
while i<=10:
if i!=7:
print(i)
i += 1
else:
i+=1
2.求1-100所有数的和
sum = 0
for i in range(1,101):
sum = sum+i
print(sum)
3.输出1-100内所有奇数
for i in range(1,101):
if i % 2 !=0:
print (i)
4.输出1-100内所有偶数
for i in range(1,101):
if i % 2 ==0:
print(i)
5.求1+3+5+....+99的和
sum=0
for i in range(1,101):
if i % 2 !=0:
sum=sum+i
print (sum)
6.用户登录(三次机会重试)
i=1
while i<=3:
user = input('请输入用户名--->')
pswd =input('请输入密码--->')
if user == 'admin' and pswd == 'admin123':
print('登陆成功')
break
else:
print('用户名或密码错误','还有', 3-i ,'次机会')
i+=1