3.9 作业

#1: 使用while循环输出1 2 3 4 5 6 8 9 10 

count = 0
while(count<10):
count+=1
if(count==7):
continue
print(count)

 

#2. 求1-100的所有数的和

count = 1
sum = 0
while count < 101:
sum = sum + count

print(sum)
  count += 1
 


#3:. 输出 1-100 内的所有奇数

count = 0
while count < 101:
if count % 2 == 1:
print(count)
count += 1


#4: 输出 1-100 内的所有偶数

count = 1
while count < 101:
if count % 2 == 0:
print(count)
count += 1


#5: 求1-2+3-4+5 ... 99的所有数的和

c = 1
s = 0
while c < 100:
temp = c % 2
if temp == 0:
s = s - c
else:
s = s + c
c += 1
print(s)


#6: 用户登陆(三次机会重试)

username = 'abc'
pwd = '123'
count = 0
while count < 3:
inp_name = input('请输入名字:')
inp_pwd = input('请输入密码:')
if inp_name == username and inp_pwd == pwd:
print('welcome')
break
else:
print('You have {x} times to try'.format(x = 2- count))
count +=1

 

 


#7::猜年龄游戏
要求:
允许用户最多尝试3次,3次都没猜对的话,就直接退出,如果猜对了,打印恭喜信息并退出

age = '19'
count = 0
while count < 3:
inp_age = input('Your age:')
if age == inp_age:
print('congratulation!!!')
break
else:
print('your are wrong')
count += 1



#8:猜年龄游戏升级版(选做题)
要求:
允许用户最多尝试3次
每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y, 就继续让其猜3次,以此往复,如果回答N或n,就退出程序
如何猜对了,就直接退出

 

posted @ 2020-03-10 02:21  NevMore  阅读(179)  评论(0编辑  收藏  举报