Sals Shipping: name error problem?

Any help is appreciated!
Receiving the following:

Traceback (most recent call last):
File “script.py”, line 59, in
print(best_method_price(4.8))
File “script.py”, line 41, in best_method_price
drone = shippingg_drone(weight)
NameError: name ‘shippingg_drone’ is not defined
Code below

def best_method_price(weight):
  
  drone = shippingg_drone(weight)
  ground = shipping_ground(weight)
  premium = shipping_premium  

  #DRONE IS BEST
  if drone < ground and drone < premium:
    method = "DRONE SHIPPING"
    best_price = drone
 #GROUND IS BEST 
  elif ground < drone and ground < premium:
    method = "GROUND SHIPPING"
    best_price = shipping_ground(weight)
 #PREMIUM IS BEST
  else:
    method = "PREMIUM SHIPPING"
    best_price = premium
  print("The best price avaliable for the weight of that item is "+ str(best_price)+ " via shipping method: "+ str(shipping_method))
    
print(best_method_price(4.8))
print(best_method_price(41.5))

Hello @spacedaddy :slight_smile:

Given your error, is shippingg_drone defined?
It is not shown in the code you posted…
Obviously this is not all of your code though.

I would recommend checking your spelling to make sure you did not name the function something else by accident.

2 Likes

Fixed it, there was an extra g in shipping_drone also found an incorrect indentation somewhere in there, looks better now but still getting NONE after print for some reason
OUTPUT:
The best price available for the weight of that item is 34.4 via shipping method: GROUND SHIPPING
None
The best price available for the weight of that item is 125.0 via shipping method: PREMIUM SHIPPING
None
INPUT:

#GROUND
def shipping_ground(weight):
  flat_charge_ground = 20.00
 #2lb
  if weight <= 2:
    cost = (1.50* weight) + flat_charge_ground
 #2-6lb
  elif weight > 2 and weight <= 6:
    cost = (3.00* weight)+ flat_charge_ground
  #6-10lb
  elif weight > 6 and weight <= 10:
    cost = (4.00* weight)+ flat_charge_ground
  #10+lb
  else:
    cost = (4.75* weight)+ flat_charge_ground
  return cost


#PREMIUM GROUND
shipping_premium = 125.00

#DRONE
def shipping_drone(weight):
  #2lb
  if weight <= 2:
    cost = (4.50* weight)
  #2-6lb
  elif weight > 2 and weight <= 6:
    cost = (9.00* weight)
  #6-10lb
  elif weight > 6 and weight <= 10:
    cost = (12.00* weight)
  #10+
  else:
    cost = (14.25* weight)
  return cost


def best_method_price(weight):
  
  drone = shipping_drone(weight)
  ground = shipping_ground(weight)
  premium = shipping_premium  

  #DRONE IS BEST
  if drone < ground and drone < premium:
    shipping_method = "DRONE SHIPPING"
    best_price = drone
 #GROUND IS BEST 
  elif ground < drone and ground < premium:
    shipping_method = "GROUND SHIPPING"
    best_price = shipping_ground(weight)
 #PREMIUM IS BEST
  else:
    shipping_method = "PREMIUM SHIPPING"
    best_price = premium
  print("The best price available for the weight of that item is "+ str(best_price)+ " via shipping method: "+ str(shipping_method))
    
#FINAL TEST
print(best_method_price(4.8))

print(best_method_price(41.5))

Hello @spacedaddy. The reason that you’re receiving None is because inside the last function:

You are printing the best price:

And, while that allows the user to see what’s going on, it doesn’t tell the program anything. That means, no data is being passed from the function to rest of the program. Therefore, when you print the result of calling the function:

You are effectively printing nothing, as the function is not returning anything to be printed.
I hope this helps!

2 Likes

Okay thank you, so would the fix be to execute best_method_price(41.5) with out print?

I think @codeneutrino is implying is that it’s printing None, when it should be printing something concrete (the clue is that it raises the question: how do I do that?)

1 Like

Hello @spacedaddy. @toastedpitabread is correct. When you try this

Does the None go away? If so, then your code works as intended.