0011_练习题d1
阅读原文时间:2023年07月15日阅读:2

__author__ = 'qq593'
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#使用while循环输入1 2 3 4 5 6 8 9 10
a=1
while True:
print(a)
if(a==10):
break
if (a==7):
a+=1
continue
a+=1

__author__ = 'qq593'
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#求1-100所有数的和
a=1
sum0=0
while(a<=100):
sum0 = sum0+a
a+=1
print(sum0)

__author__ = 'qq593'
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#输出1-100内所有奇数
a=1
while(a<101):
if(a%2!=0):
print(a)
a+=1

__author__ = 'qq593'
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#输出1-100内所有偶数
a=1
while(a<101):
if(a%2==0):
print(a)
a+=1

__author__ = 'qq593'
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#求1-2+3-4+5….99的所有数的和

#方法一

sumj = 0

sumo = 0

i = 1

while(i<100):

if(i%2==0):

sumo+=i

else:

sumj+=i

i+=1

print(sumj-sumo)

#方法二:
i=1
he=0
while(i<100):
if(i%2==1):
he+=i
else:
he-=i
i+=1
print(he)

__author__ = 'qq593'
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#用户登录(三次机会重试)
wtime=1
while(wtime<=3):
user = input("Username:")
pwd = input("Password:")
if (user!="xb" or pwd!=""):
print("Username or Password wrong,Please input again!(%d/3)"%wtime)
wtime+=1
else:
print("Login Succeed!")
break