Hi People,
just a quick one (hopefully). I keep getting this error message when trying to run the function and print. I’m following the video tutorial and seem to keep getting it. Anyone see why its happening from my code?
Thank you
Traceback (most recent call last):
File “script.py”, line 44, in
% (cost, method)
NameError: name ‘cost’ is not defined
premium_ground_ship = 125.00
def cost_of_ground(weight):
if weight <= 2:
return (1.50weight + 20)
elif weight <=6:
return (3.00weight + 20)
elif weight <=10:
return (4.00weight + 20)
else:
return (4.75weight + 20)
print(cost_of_ground(8.4))
def cost_of_drone(weight):
if weight <= 2:
return (4.50weight)
elif weight <=6:
return (9.00weight)
elif weight <=10:
return (12.00weight)
else:
return (14.25weight)
print(cost_of_drone(1.5))
def print_cheapest_method(weight):
ground = cost_of_ground(weight)
drone = cost_of_drone(weight)
premium = premium_ground_ship
if drone< ground and drone< premium:
method = “standard drone”
cost = drone
elif ground< premium and ground< drone:
method = “standard ground”
cost = ground
else:
method = “premium ground”
cost = premium
print(
"The cheapest method cost is $%.2f and it is %s delivery "
% (cost, method)
)
print_cheapest_method(4.8)
print_cheapest_method(41.5)