python字典的运用

img

img

这个python的字典题写不出来啊,目前在自学python,求解

product_items = {
    '10000101': '绞线机',
    '10000102': '光标机',
    '10000103': '端子机',
    '10000104': '绕线机',
    '10000105': '点阵机',
    '10000110': '点锡机',
    '10000112': '绕线螺母',
}
# ####第1题
print("全部产品为:", product_items)

# ####第2题
product = input('请输入商品编号:')
if product.strip() not in product_items:
    print("无此编号的产品")
else:
    print('编号对应的产品为:', product_items[product])

# ####第3题
product_items['10000104'] = '绕线端子机'
product_items.pop('10000112')
print('修改删除之后的产品列表:', product_items.values())

有帮助的话,请点采纳该答案~


dict = {101: 'jxj',
        102: 'gbj',
        103: 'dzj',
        104: 'rxj'}
print(dict)  # 输出
i = int(input())
for j in dict.keys():
    if i == j:
        print(i)
        break
else:
    print("无此编号的产品")

dict[104] = '绕线端子机'  # 修改
del dict[102]  # 删除
print(dict.values())

希望对你有帮助哦!

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^