A day at the supermarket 11/13 Making a Purcahse


So here is my code...

def computeBill(food):
    total = 0
for item in food:
    total = total + prices[item]
        return total
print computeBill

and is keeps saying that return is an outside function. What is with Python? I have had elif and else statements say that and now it's return? This is so buggy....It's frustrating :frowning:
Can someone please help me?



Is your return (the word) in line with for (the word)?
It is indentation.


python relies on indention (spacing) for nesting. your for loop is outside the function:

def example():
    print "loop outside the function"
for something in somethings:

loop inside the function:

def example():
    print "loop inside the function"
    for something in somethings:

check the indent of your code, at this point in the course, this shouldn't be something new


You wrote computeBill(food), when you were supposed to write compute_bill(food)


Indentation should be corrected.
total = total + prices[item] needs to be replaced with the following:
total = total + float(prices[item])



posting about indention but not using markup so indention doesn't show? Doesn't sound like a good idea, the float casting seems unnecasary.


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