#_author:来童星
#date:2019/12/10
#1.
year=[89,98,00,75,68,37,58,90]
for index,value in enumerate(year):
if str(value)!='0':
year[index]=int('19'+str(value))
else:
year[index]=int('200'+str(value))
year.sort()
print(year)
# 2
#(1
this_week=[4235,10111,8774,9566,9788,8951,9808]
print('本周步数列表',this_week)
# (2
last_week=[4235,5612,8447,1150,9211,9985,3783]
print('上周步数列表',last_week)
#(3
sum_week=[]
for a,b in zip(this_week,last_week):
sum=a+b
sum_week.append(sum)
print(sum_week)# [8470, 15723, 17221, 10716, 18999, 18936, 13591]
sum_week.sort()
print('升序:',sum_week)# 升序: [8470, 10716, 13591, 15723, 17221, 18936, 18999]
print('降序:',sorted(sum_week,reverse=True))# 降序: [18999, 18936, 17221, 15723, 13591, 10716, 8470]
#(4
day=['周日','周一','周二','周三','周四','周五','周六']
print('星期列表:',day)# 星期列表: ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
x=this_week.index(max(this_week))
y=this_week.index(min(this_week))
day.insert(x+1,max(this_week))
day.insert(y+1,min(this_week))
print(day)# ['周日', 4235, '周一', 10111, '周二', '周三', '周四', '周五', '周六']
#(6
print('=============')
week_day=['周日','周一','周二','周三','周四','周五','周六']
thislist1=[]
thislist2=[]
for item in this_week:
if item>8000:
thislist1.append(item)
i=this_week.index(item)
thislist2.append(week_day[i])
print('本周高于8000步的步数值',thislist1)
print('本周高于8000步的日期',thislist2)
thislist1=[]
thislist2=[]
for item in last_week:
if item>8000:
thislist1.append(item)
i=last_week.index(item)
thislist2.append(week_day[i])
print('本周高于8000步的步数值',thislist1)
print('本周高于8000步的日期',thislist2)
# this_week=[4235,10111,8774,9566,9788,8951,9808]
# last_week=[4235,5612,8447,1150,9211,9985,3783]
# print(sum(last_week))
# print(sum(this_week))
# 3
list1=[]# 存放输入的商品信息
for i in range(5):
inp=input('请输入商品编号和商品名称进行商品入库,每次只能输入一件商品:')
list1.append(inp)# 将输入的商品信息存放到list中
for item in list1:
print(item)#输出所有商品信息
car=[]# 存放购物车商品信息
num2=0
while True:
num1=input('请输入要购买的商品的商品编号:')
for item in list1:
if item.find(num1)==0:#!!!!! 在item中有num1的话就执行if内的语句,该语句等价于 if item.find(num1)!=-1
num2=item
car.append(num2)# 购物车商品信息存放到car中
print('商品已加入购物车,请继续输入要购买的商品的商品编号:')
break
if num1 == 'q':
break
print('您购物车里已经选择的商品为:')
for i in range(len(car)):#!!!!!
print(car[i])