作业
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)
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