Fuction call "error"


#1

My code:

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 key in food:
        if stock[key] > 0:
            total += prices[key]
            stock[key] -= 1            
    return total
        
shopping_list = ["banana", "orange", "apple"]
print compute_bill(shopping_list)

Result:
5.5
None

Error reported:

Oops, try again. stock doesn't look quite right! Make sure to not call compute_bill since it changes the stock! It should contain: {'orange': 32, 'pear': 15, 'banana': 6, 'apple': 0}

As the exercise ask, I change the stock at the same fuction, but should it be modified from another function outside compute_bill? or should we use a temporary variable to modify the stock?


#2

Please re-edit your Post

  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.


#3

Thanks for thev advise!


#4

As the Oops-message makes it clear,
that you must NOT execute the computebill()_ function,
replace your

print compute_bill(shopping_list)

with

#print compute_bill(shopping_list)