1.使用while循环输出1 2 3 4 5 6 8 9 10
答:count=0
while count <11:
if count ==7
count+=1
cootinue
print(count)
count+=1
2.求1-100的所有数的和
答:s=0
count=0
while count <=100
s = s+count
count=count+1
print(s)
3.输出1-100内的所有奇数
答:for i in range (1,100,2)
print(i)
4.输出1-100内的所有偶数
答:count=1
while count<=100
if count%2==0
print(count)
coumt+1
5.求1-2+3-4+5...99的所有数的和
答:e=1
s=0
while e <100:
if e%2==0:
s-=e
else:
s+=e
e+=1
print(s)
6:用户登录(三次机会重试)
答:print(‘start---’)
count=0
whine count<3:
name=input(‘your name---‘)
pwd=input(‘your password---‘)
if name ==‘tom‘ amd pwd==‘123‘
print(‘login successful‘)
break
else:
print(‘user or password’)
count+=1
7.猜年龄
答:count=0
while count<3
age=ipnut(‘my age?-----’)
if age ==‘18‘ :
print(’恭喜猜对了‘)
break
else:
print(‘user or parssword’)
count+=1
8.
答:age_of_boy=18
count=0
while True:
if count==3
choice=input(‘继续(Y/y?)---)
if choice ==’Y‘ or choice=‘y’:
count=0
else:
break
guess=int(input(‘----‘))
if guess ==age of boy:
print(‘恭喜猜对了’)
break
break
原文:https://www.cnblogs.com/wuzhengzheng/p/9652262.html