#s1 = {1,2,3,1} """ s2 = ([2,5,6]) print(s1) s1.add(5) #添加元素"5" print(s1) s3 = s1.difference(s2) #返回一个s1中存在而不存在于s2的字典 print(s3) """ #s1.discard(1) #删除元素"1" #print(s1) #s1.remove(3) # #print(s1) #s1.update([11, 2, 3]) #更新s1的元素,添加 #print(s1) #s1.pop() #删除元素,无序的,所以不知道删除谁,随机的 #print(s1) #-------------------------分割线-------------------------- ##s2 = {3,4,5,6} #r1 = s1.intersection(s2) # 取交集,并返回一个新的交集 r1={3,4} #print(r1) #s1.intersection_update(s2) #取交集,并将s1更新为取交集的结果 s1={3,3} #print(s1) #s1.issubset(s2) #print(s2)
1 li = ["手机","电脑","鼠标垫","游艇"] for i,j in enumerate(li): print(i+1,j)
num= input("num:") num = int(num) len_li = len(li) if num >0 and num < len_li: good = li[num-1] print(good) else: print("商品不存在")
--------------分割线-----------------
asset_all = 1999 car_list = [] i1 = input('请输入总资产:') asset_all = int(i1) goods = [ {"name":"电脑","price":1999}, {"name":"鼠标","price":10}, {"name":"游艇","price":20}, {"name":"美女","price":998}, ] for i in goods: print(i['name'],i['price']) while True: i2 = input('请输入商品:') if i2 == "y": break for j in goods: if j ['name'] == i2: car_list.append(j) print(car_list) all_price = 0 for item in car_list: p = item['price'] all_price = all_price + p print(asset_all,all_price) if all_price > asset_all: print('你个穷逼') else: print("购买成功")