Stocking Out pls help


"Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 9 instead of the correct 7" I am getting this error message

def compute_bill(food):
    for item in food:
    return total
    for item in food:
        if stock[item] > 0:
            total += prices[item]
            stock[item] -= 1
    return total


a function ends the moment a return keyword is reached.

this means, currently, you don't check if item is present in stock, and you don't reduce stock after you bought an item


what is the solution for this error ??


only have a single loop in which you increase total and reduce stock, then after the loop return total


Please write the code to show us how it's done. Am waiting for it please. My code is showing that it's not giving correct figure 7


this is a violation of the guidelines, make a new topic so we can help you


But it's on same stocking out issue! Should we be duplicating post when similar unclosed thread still exist?


if i recommend you to make a new topic, then the answer to this question is: Yes, you should.

Otherwise this topic becomes cluttered, making it much more difficult for other users to find what they need. Making new topic will also be seen by more people


Your loop through the food is being duplicated and doesn't make sense since both loops return the same result. Delete the first 'for loop' and its executables and you should be fine.


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