shangpinchengyu = ["手机", "电脑", "鼠标垫", "游艇" ] while 1==1: choose = input("需要添加商品序号请按1,需要选择商品请按2,需要展示所有商品请按3") if(choose=="1"): xuhao = int(input("请输入你要选择的商品序号")) if(xuhao>=len(shangpinchengyu)): print("输入不正确") continue print(shangpinchengyu[xuhao]) elif(choose=="2"): shangpin = input("请输入要添加的商品") for item in shangpinchengyu: if(item == shangpin): print('商品已存在') continue shangpinchengyu.append(shangpin) elif (choose == "3"): for item in shangpinchengyu: print(item) else: print("输入不正确")
arr=[11,22,33,44,55,66,77,88,99,90] dict1 = {'key1':[],'key2':[]} for item in arr: if(item<66): dict1["key1"].append(item) else: dict1["key2"].append(item)
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did170073