标签:名称 efault 要求 购物车 列表 name 删除 split 选中
content = input("请输入内容:") for i in content: if i.isalpha(): content = content.replace(i, " ") s = content.split() print(len(s))
li = [11, 22, 33, 44, 55, 66, 77, 88, 99, 90]
dic = {"k1": [], "k2": []}
for i in li:
if i > 66:
dic["k1"].append(i)
elif i == 66:
continue
else:
dic["k2"].append(i)
print(dic)
while 1: li = ["手机", "电脑", ‘鼠标垫‘, ‘游艇‘] for i in li: print(li.index(i) + 1, i) content = input("请输入商品序号:") if content.isdigit(): content = int(content) if content > 0 and content <= len(li): print(li[content - 1]) else: print("请输入有效数字") elif content.upper() == "Q": print("退出程序") break else: print("输入有误,请重新输入:")
li = [ {"name": "苹果", "price": 10}, {"name": "西瓜", "price": 31}, {"name": "菠萝", "price": 24}, {"name": "香蕉", "price": 20} ] shopping_car = {} print("欢迎光临小赖水果店") money = input("让我看看你的钱:") while 1: for i, k in enumerate(li): print("序号{},商品{},价格{}".format(i, k["name"], k["price"])) choose = input("请输入要购买商品的序号:") if choose.isdigit() and int(choose) <= int(len(li)): num = input("请输入要购买的数量:") if num.isdigit(): if int(money) >= li[int(choose)]["price"] * int(num): money = int(money) - li[int(choose)]["price"] * int(num) if li[int(choose)]["name"] in shopping_car: shopping_car[li[int(choose)]["name"]] = shopping_car[li[int(choose)]["name"]] + int(num) else: shopping_car[li[int(choose)]["name"]] = int(num) print("购物车中的商品有{},您的余额还有{}".format(shopping_car, money)) else: print("穷鬼,回去找你老婆要钱去吧") else: print("您输入有误") else: print("请你输入正确的序号") continue
# 方法一: dic = {"k1": "aa", "kf": "cc", "aw": "gg", "3k": "dd"} dic2 = {} for i in dic: if "k" not in i: dic2.setdefault(i, dic[i]) dic = dic2 print(dic) # 方法二: dic = {"k1": "aa", "kf": "cc", "aw": "gg", "3k": "dd"} li = [] for i in dic: if "k" in i: li.append(i) for i in li: del dic[i] print(dic)
标签:名称 efault 要求 购物车 列表 name 删除 split 选中
原文地址:https://www.cnblogs.com/lin961234478/p/10327320.html