# Making a purchase why does this work

#1

shopping_list = ["banana", "orange", "apple"]

stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}

def compute_bill(food):
total = 0
for foods in food:
if stock[foods] >= 0:
total = total + prices[foods]

for some reason it wont accept it if i just leave it as if stick[foods] > 0, it doesn't make sense to me that it wants to add the price of apples even though there are none in stock can someone please explain this to me?

#2

seems you are running ahead? The track is broken into smaller pieces to not be overwhelming, checking if product is in stock and reducing stock after product is bought is for next exercise

#3

oops i just realised that the exercise i did wasnt stocking out it was actually called "making a purchase", regardless tho it said that the value of apple had to be 2 instead of zero but that doesn't make any sense at all to me

#4

True, it doesn't. That is why you will fix checking if item is in stock in the next exercise, if we throw everything at once at you, that might be overwhelming, so the exercises are broken down into smaller steps

for now, don't check if the item is in stock, that will come in next exercise

#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.