10-12 Don't Call The Function...?


#1



A day at the supermarket, stocking out.

I'm getting the error message reading to not call your function in the code, I've seen this in other posts as the answer to my problem. But to evaluate the lists I have to call the function right? This is where I'm struggling. The problem says to remove one item from the stock but the error message says don't call the function because the function manipulates the stock, but the problem says to manipulate the stock by removing 1... gah!

I love learning this stuff but it's a constant state of feeling dumb... below is my code.

Thanks!

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}


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


#2

When you call the function it changes the stock. This means the SCT will not see the value it expects. That is why it explicitly directs us NOT to call the function for this exercise.


#3

Ok, but doesn't the function evaluate the lists and make the modifications required by the problem?

Do I need a separate function to reduce the stock?

To my brain, problem says evaluate list and modify, to do that I need to call a function to evaluate and modify. Error code says don't call function, but to me that's the only way to do what the problem requires?


#4

It's only this one lesson that the SCT needs to examine in its original form. The next exercise will carry on from here.


#5

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