Clothes Shop¶
A clothing manufacturing company uses a stock dictionary for each
shop. In this dictionary (dict), each key is a
3-tuple with the code, size and color of a model of a piece
of clothing (3 str) and the value is the number of pieces of
this model that are in the shop (int).
Save all functions into the same file named clotheshop.py.
Write the modifier function
stock_increase()that given a stock dictionary, the code (str), size (str) and color (str) of a model, and a number of pieces of this model(int), modifies the dictionary adding this quantity to the given model.>>> d = {('Pan85', 'XS','black'):100,('Pan85','S','black'):300, ... ('Pan85','XS','blue'):6,('Pan87','S','blue'):5, ... ('Pan87','L','blue'):12} >>> stock_increase(d,'Pan85','S','black',10) >>> if d != {('Pan85', 'XS','black'):100,('Pan85','S','black'):310, ... ('Pan85','XS','blue'):6,('Pan87','S','blue'):5, ... ('Pan87','L','blue'):12}: ... print(d) >>> stock_increase(d,'Pan85','M','black',10) >>> if d != {('Pan85', 'XS','black'):100,('Pan85','S','black'):310, ... ('Pan85','XS','blue'):6,('Pan87','S','blue'):5, ... ('Pan87','L','blue'):12,('Pan85','M','black'):10}: ... print(d)
Note
More tests are provided in
test-shop1.txtWrite the modifier function
stock_decrease()that given a stock dictionary, the code (str), size (str) and color (str) of a model, and a number of pieces of this model (int), modifies the dictionary subtracting this quantity to the given model. We will suppose that there are always enough pieces to subtract the given quantity.>>> d = {('Pan85', 'XS','black'):100,('Pan85','S','black'):300, ... ('Pan85','XS','blue'):6,('Pan87','S','blue'):5, ... ('Pan87','L','blue'):12} >>> stock_decrease(d,'Pan85','XS','blue',2) >>> if d != {('Pan85', 'XS','black'):100,('Pan85','S','black'):300, ... ('Pan85','XS','blue'):4,('Pan87','S','blue'):5, ... ('Pan87','L','blue'):12}: ... print(d)
Note
More tests are provided in
test-shop2.txtWrite the function
low_stock()that given a stock dictionary and a threshold (int), returns alistwith those pieces with a stock lower than the given threshold. Each piece in the returnes list is represented with a tuple with the code, size and color.>>> d = {('Pan85', 'XS','black'):100,('Pan85','S','black'):300, ... ('Pan85','XS','blue'):6,('Pan87','S','blue'):5, ... ('Pan87','L','blue'):12,('Pan85','M','white'):6, ... ('Pan85','L','white'):5,('Cam23','XL','white'):12} >>> lresult = low_stock(d,10) >>> lresult.sort() >>> lresult [('Pan85', 'L', 'white'), ('Pan85', 'M', 'white'), ('Pan85', 'XS', 'blue'), ('Pan87', 'S', 'blue')]
Note
More tests are provided in
test-shop3.txtA sales list is a nested list. Each sublist of it has the code, color and size of a model (3
str) and the number of sold pieces of this model (int). A restocking list is similar to a sales list but the amount means the number of restoked models. Write the modifier functionupdate_stock()that given a stock dictionary, a sales list, and a restocking list, modifies the dictionary subtracting those sales of the first list and adding the restock of the second one.This function must use the previous functions
stock_increase()and py:func:stock_decrease.>>> d = {('Pan85', 'XS','black'):100,('Pan85','S','black'):300, ... ('Pan85','XS','blue'):6,('Pan87','S','blue'):5, ... ('Pan87','L','blue'):12,('Pan85','M','white'):6, ... ('Pan85','L','white'):5,('Cam23','XL','white'):12} >>> lsales = [['Pan87','S','blue',3],['Cam23','XL','white',9], ... ['Pan87','L','blue',1]] >>> lrstock = [['Pan87','L','blue',5],['Cam23','S','blue',5]] >>> update_stock(d,lsales,lrstock) >>> if d != {('Pan85', 'XS','black'):100,('Pan85','S','black'):300, ... ('Pan85','XS','blue'):6,('Pan87','S','blue'):2, ... ('Pan87','L','blue'):16,('Pan85','M','white'):6, ... ('Pan85','L','white'):5,('Cam23','XL','white'):3, ... ('Cam23','S','blue'):5}: ... print(d)
Note
More tests are provided in
test-shop4.txt
Solutions
A solution is provided in the clotheshop.py.