A day at the supermarket 11/13 Making a Purcahse


#1

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?


#2

Hello

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


#3

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


#4

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


#5

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

HTH


#6

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


#8

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