py仓库数格式问题如何解决

img


7、编写代码,按要求完成以下功能
题目:
你现在是仓库的负责人,仓库数格式为:

total={
"sku": ["SKU-A" "SKU-B", "SKU-C", "SKU-D"]}, quantity: [100,200,300,400]


total={
    "sku": [ "SKU-A","SKU-B", "SKU-C", "SKU-D" ],
    'quantity': [100,200,300,400]
}

# 第1问
current_quantity = sum( total.get('quantity') )
print('当前已经存放{}件商品,库存余量为{}件'.format( current_quantity,1500-current_quantity ))

# 第2问
aIndex = total.get('sku').index('SKU-A')
total.get('quantity')[aIndex] = total.get('quantity')[aIndex] + 100
print(total)


# 第3问
total.get('sku').append('SKU-E')
total.get('quantity').append(300)
print(total)

# 第4问
cIndex = total.get('sku').index('SKU-C')
del total.get('sku')[cIndex]
del total.get('quantity')[cIndex]
print(total)

# 第5问
plan_quantity = 800
total_quantity = sum( total.get('quantity') ) + plan_quantity
if total_quantity > 1500:
    print('SKU-F新品不可以入库')
else:
    total.get('sku').append('SKU-F')
    total.get('quantity').append(plan_quantity)


# 第6问
del total.get('sku')[-1]
del total.get('quantity')[-1]
print(total)