 # Sal's shipping! Confusion about output - None

So I don’t understand why, and I’ve looked around, but for some reason, the output of my last function, when specified as 41.5lb, is “None”. I don’t see any reason fo it to do so. Could you help please?

``````
def ground_ship(weight):
if weight < 2:
cost = 1.50
charge = weight * cost
elif 2 < weight <= 6:
cost = 3.00
charge = weight * cost
elif 6 < weight <= 10:
cost = 4.00
charge = weight * cost
else:
cost = 4.75
charge = weight * cost
total_charge = charge + 20

def drone_ship(weight):
if weight < 2:
cost = 1.50 * 3
charge = weight * cost
elif 2 < weight <= 6:
cost = 3.00 * 3
charge = weight * cost
elif 6 < weight <= 10:
cost = 4.00 * 3
charge = weight * cost
else:
cost = 4.75
charge = weight * cost
total_charge = charge

def lowest_price(weight):
ground_price = ground_ship(weight)
drone_price = drone_ship(weight)
if ground_price > drone_price:
print("The lowest price is from shipping by drone:")
return drone_price

elif drone_price > ground_price:
print("The lowest price is from shipping by ground:")
return ground_price
print("The lowest price is from shipping premium:")

print(lowest_price(41.5))

``````

Also please don’t remark about cutting down on use with e.g. the repeated “charge =”
I know, but that isn’t the issue at hand.
Thanks a lot :DD

None is the absence of a return value. And due to the lack of information being printed, its safe to assume none of your conditions evaluate to true

1 Like

So how would I fix that, because I don’t see why the last part isn’t being used? The else at the end of the function, namely:

``````elif premium < drone_price and premium < ground_price:
print("The lowest price is from shipping premium:")

maybe start with printing all the variables used in this comparison and see why its not going right? And you are not using `else`, you use `elif` (another condition)

1 Like

Because the first `if` evaluates to true.

The following `if` does not, so your function returns the default (i.e. unspecified) value of `None`.

``````def ground_ship(weight):
if weight < 2:
cost = 1.50
charge = weight * cost
elif 2 < weight <= 6:
cost = 3.00
charge = weight * cost
elif 6 < weight <= 10:
cost = 4.00
charge = weight * cost
else:
cost = 4.75
charge = weight * cost
total_charge = charge + 20

def drone_ship(weight):
if weight < 2:
cost = 1.50 * 3
charge = weight * cost
elif 2 < weight <= 6:
cost = 3.00 * 3
charge = weight * cost
elif 6 < weight <= 10:
cost = 4.00 * 3
charge = weight * cost
else:
cost = 4.75
charge = weight * cost
total_charge = charge

def lowest_price(weight):
ground_price = ground_ship(weight)
drone_price = drone_ship(weight)
if ground_price > drone_price:
print("Ground price > drone price")
print("The lowest price is from shipping by drone:")
return drone_price
elif drone_price > ground_price:
print("Drone price > ground price")
print("The lowest price is from shipping by ground:")
return ground_price
print("The lowest price is from shipping premium:")

print(lowest_price(41))
``````

Console output is:

``````Ground price > drone price
None
``````

Because that first `if` is true, it doesn’t matter what the rest of the `elif`s do - they’ll never be executed.

1 Like

Thank you guys for your replies! I finally managed to get it working with this, do you see why it now works?

``````def ground_ship(weight):
if weight < 2:
cost = 1.50
charge = weight * cost
elif 2 < weight <= 6:
cost = 3.00
charge = weight * cost
elif 6 < weight <= 10:
cost = 4.00
charge = weight * cost
else:
cost = 4.75
charge = weight * cost
total_charge = charge + 20

def drone_ship(weight):
if weight < 2:
cost = 1.50 * 3
charge = weight * cost
elif 2 < weight <= 6:
cost = 3.00 * 3
charge = weight * cost
elif 6 < weight <= 10:
cost = 4.00 * 3
charge = weight * cost
else:
cost = 4.75
charge = weight * cost
total_charge = charge

def lowest_price(weight):
ground_price = ground_ship(weight)
drone_price = drone_ship(weight)
if ground_price > drone_price and premium > drone_price:
print("Shipping by drone is cheapest:")
return drone_price
elif drone_price > ground_price and premium > ground_price:
print("Shipping by ground is cheapest:")
return ground_price