1 字典dic = {'k1':"v1",'k2'="v2","k3":[11,22,33]}
dic = {'k1':"v1",
'k2':"v2",
"k3":[11,22,33]}
# 1)循环输出所有的key
# for i in dic.keys():
# print(i)
# 2)循环输出所有的value
# for i in dic.values():
# print(i)
# 3)循环所有的key与value
# for k,v in dic.items():
# print(k,v)
# 4)在字典中添加一个键值对,‘k4’:'v4'
# dic['k4']='v4'
# dic.setdefault('k4','v4')
# 5)请在修改字典中‘k1’对应的值为‘alex’
# 1.dic['k1']='alex'
# 2.dic1 = {'k1':'alex'}
# dic.update(dic1)
# 6)在k3对应的值中追加一个元素44
# dic['k3'].append(44)
# 7)在k3对应的值的第一个位置插入一个元素18
#dic['k3'].insert(0,'18')
2)元素分类 有如下值li=[11,22,33,44,55,66,77,88,99,90],将所有大于等于66的值保存至
字典的第一个key中,将小于66的值保存至第二个key值中
# li=[11,22,33,44,55,66,77,88,99,90]
# dic = {'key1':[],'key2':[]}
# for i in li :
# if i >= 66:
# dic['key1'].append(i)
# else:
# dic['key2'].append(i)
# print(dic)
3)输出商品列表,用户输入序号,显示用户选中的商品
商品li = ["手机","电脑","鼠标垫","游艇"]
要求: 1:页面显示 序号+商品名称 如:
1 手机
2 电脑
...
2:用户输入选择的商品序号,然后打印商品名称
3:如果用户输入的商品序号有误,则提示输入错误
4:用户输入Q或q,退出程序
li = ["手机","电脑","鼠标垫","游艇"]
msg = '''
1:页面显示
2:查询商品信息
Q:退出系统
'''
while 1:
operate = input("请输入您需要的操作"+msg)
if operate == '1':
for i in li :
print(li.index(i)+1,i)
elif operate == '2':
order = int(input("请输入商品序号"))-1
if order > 3 or order<1:
print("序号有误")
break
else :
print(order+1,li[order])
elif operate.lower() =='q':
break
else:
operate = input("输入有误,重新输入")