Sal shipping name not defined

I have defined cost but it is showing name error
And i have checked it from video ot is exactly same cost is highlighted in the programme. I would really appreciate if you reply.

It’s kind of hard to see what’s going on from the screenshot, can you copy and paste the code when you have a chance?

Usually this would probably happen when the invocation of the variable is calling for it in the wrong scope, or it’s undefined from not getting a value in the conditional logic.

1 Like

def ground_shipping(weight):
if weight <= 2:
price_per_pound = 1.50
elif weight <= 6:
price_per_pound = 3.00
elif weight <= 10:
price_per_pound = 4.00
price_per_pound = 14.25
return 20 + (price_per_pound * weight)
print( ground_shipping(8.4))
cost_of_p_ground_shipping = 125.00
def drone_shipping(weight):
if weight <= 2:
price_per_pound = 4.50
elif weight <= 6:
price_per_pound = 9.00
elif weight <= 10:
price_per_pound = 12.00
price_per_pound = 14.25
return (price_per_pound * weight)

def cheapest_shipping(weight):
ground = ground_shipping(weight)
premium = cost_of_p_ground_shipping
drone = drone_shipping(weight)

if ground < premium and ground < drone:
method = “Ground Shipping”
cost = ground
elif premium < ground and premium < drone:
method = “Premium Ground Shipping”
cost = premium
(drone < ground) and (drone < premium)
method = “Drone Shipping”
cost = drone
print ( “You Should Ship Using %s , it will cost %.2f”

% (cost,method)

You also would need to format it with the </> button before pasting.

This matters because of the nature of the error. Depending on the spacing/tabbing of certain lines it will throw an error or it may not.


Where i should put </>

See here.

1 Like

I didn’t undertood because it is for html

Code Blocks

Toolbar Icon
Using Preformatted Text icon on the toolbar

This will automatically create a code block which you can paste your code in.
Or select your code and then press the icon.