Problem with printing the TOTAL (STOCKING OUT)


#1

Hi Pals,

I need small clarification.Why am I not getting the output TOTAL in the console window even I have finished that assignment properly.

In the below given program, I have tried in two way like having 1)both the "return" and "print" statement together, 2)"print" command alone as given below.But,still not getting the total in the screen.

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=total+prices[item]
            stock[item]=stock[item]-1
    #return total
    print total

Thanks!


#2

Hello :slight_smile:

You have to call / execute your function. To do that you need to pass some value as a food parameter. Example:

compute_bill(shopping_list)

#3

@factoradic Thank you very much!
I made that last line into comment...lolzzz...


#4

You're very welcome :slight_smile:


#5

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