Подскажите, пожалуйста, с задачей:
Stocking Out
Now you need your compute_bill function to take the stock/inventory of a particular item into account when computing the cost.
Ultimately, if an item isn't in stock, then it shouldn't be included in the total. You can't buy or sell what you don't have!
Instructions
Make the following changes to your compute_bill function:
While you loop through each item of food, only add the price of the item to total if the item's stock count is greater than zero.
If the item is in stock and after you add the price to the total, subtract one from the item's stock count.
?
Hint
If you're buying a banana, check if it's in stock (larger than zero). If it's in stock, add the cost of a banana to your bill. Finally, decrement the stock of bananas by one!
По условиям задачи если искомый фрукт находится в инвентаре (stock), то есть больше 0, то тогда он добавляется к общему счету (функция compute_bill) и вычитается из общего stock'а нужного объекта (банан, яблоко и т.п.).
Мой код выглядит так:
shopping_list = ["banana", "orange", "apple"] stock = { "banana": 6, "apple": 0, "orange": 32, "pear": 15 } prices = { "banana": 4, "apple": 2, "orange": 1.5, "pear": 3 } # Write your code below! def compute_bill(food): total = 0 for item in food: if stock(item) > 0: total = prices[item] + total return stock[item] - 1 return total
на что выдается ошибка:
Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana caused the following error: ‘dict’ object is not callable
Users/fomichevll/AppData/Local/Programs/Python/Python35/ввввввввв.py”, line 25, in <module>