from itertools import combinations_with_replacement
cafes = {
'卡布奇诺': 32,
'摩卡': 30
}
cakes = {
'抹茶蛋糕': 28,
'布朗尼': 26
}
def get_combo(cafeNum: int, cakeNum: int) -> dict:
"""获取咖啡和蛋糕单品组合套餐价格表
单品定义于公共字典cafes和cakes
:param cafeNum: 套餐内咖啡杯数
:param cakeNum: 套餐内蛋糕个数
:return: dict
"""
ret = {}
price_list = cafes.copy()
price_list.update(cakes)
for cafe in combinations_with_replacement(cafes.keys(), cafeNum):
for cake in combinations_with_replacement(cakes.keys(), cakeNum):
price = sum((price_list[p] for p in cafe + cake))
ret['+'.join(cafe+cake)] = price
return ret
c = get_combo(2, 2)
|