作业

01

li = [11,22,33,44,55,66,77,88,99,90]#将66以下的保存到第一个key键,66及以上的保存到key2.
l = {}
less = []
more = []
for i in li:
    if i < 66:
        less.append(i)
    else:
        more.append(i)
l.setdefault('more',more)
l.setdefault('less',less)
print(l)
View Code

02 购物车部分

通过输入商品序号从而打印商品名称

while 1:
    li = ['手机','电脑','键盘','鼠标']
    for i in li:
        print("{}  {}".format(li.index(i)+1,i))
    user = input("请输入序号/输入q或Q退出:")
    if user.isdigit():
        user = int(user)
        if user > 0 and user < len(li):
                print(i)
        else:
                print("请输入有效数字")
    elif user.upper() == 'Q':
        break
View Code

 

posted @ 2019-07-22 23:03  套你大象  阅读(86)  评论(0编辑  收藏  举报