1、使用while循环输入:1 2 3 4 5 6 8 9 10
count = 0
while count< 10:
count=count+1
if count == 7:
pass
else:
print(count)
2、求1-100的所有数的和
count = 0
sum=0
while count < 101:
sum=count+sum
count=count+1
if count>=101:
print(sum)
3、输出1-100内的所有奇数
count = 0
while count < 101:
count=count+1
n=count % 2
if n==0:
pass
else:
print(count)
4、输出1-100内所有偶数
count = 0
while count < 101:
count=count+1
n=count % 2
if n!=0:
pass
else:
print(count)
5、求1-2+3-4+5...99的所有数的和
n=1
s=0
while n<100:
temp=n%2
if temp==0:
s=s -n
else:
s=s+n
n=n+1
print(s)
6、用户登录(三次机会登录)
count=0
while count<3:
user=input(">>>")
pwd=input(">>>")
if user=="admin"and pwd=="admin":
print("登录成功")
break——————————————————————————————————————————执行成功就直接跳出这个while循环
else:
print("用户名或密码错误")
count=count+1