Sal's Shipping project

I was having trouble on the Sal’s shipping project and I looked at some community forums for help and got the correct code and now I’m trying to find what I did wrong. This is what I put:

return cost


And this is what I get:

File “”, line 8
return cost
SyntaxError: ‘return’ outside function

Can someone help me with this and say what I’m doin wrong?

Study you code closely and be sure that you are not using return incorrectly.

def foo(x):
    return x

If the keyword is used outside of a function body, it will raise a syntax error.

1 Like

Hello, Where am I making an error in the below code? I keep getting the answer - None. Please advise!!

def cost_ground (weight):

Ground Shipping

if weight <= 2:
cost_ground == weight * 1.50 + 20
elif weight <= 6:
cost_ground == weight * 3.00 + 20
elif weight <= 10:
cost_ground == weight * 4.00 + 20
cost_ground == weight * 4.75 + 20

Your function is named cost_ground so it is confusing why the same name is given to the internal variable. I would change that, for starters.

Also, == is not assignment, but comparison.

cost = weight * 1.50

If the printing is being done inside the function, then there is no return value to use elsewhere after the function call. But if the print statement is as we see it, and it is outside of the function, then it appears to be expecting a return value to print.

return cost + 20

Note that since the base amount is the same for all four cases, we can tack it on at the return stage.

Got it! Thank you so much for quick response!

1 Like