Sal's Shipping Help

Whenever I run my code I get three Nones.

``````def ground_shipping(weight):
if (weight > 10):
ground_shipping == (weight * 4.75) + 20
elif (weight > 6 and weight <= 10):
ground_shipping == (weight * 4) + 20
elif (weight > 2 and weight <= 6):
ground_shipping == (weight * 3) + 20
else:
ground_shipping == (weight * 1.5) + 20

print(ground_shipping(2))

def drone_shipping_cost(weight):
if (weight > 10):
drone_shipping_cost == weight * 14.25
elif (weight > 6 and weight <= 10):
drone_shipping_cost == weight * 12
elif (weight > 2 and weight <= 6):
drone_shipping_cost == weight * 9
else:
drone_shipping_cost == weight * 4.50

print(drone_shipping_cost(9))

premimum_ground_shipping = weight + 125

def cheapest(weight):
if (ground_shipping < prenium_ground_shipping and drone_shipping_cost):
print("Ground shpping is the cheapest. Ground shipping cost " + str(ground_shipping))
elif (prenium_ground_shipping < ground_shipping and drone_shipping_cost):
print("Prenium ground shipping is the cheapest. Prenium ground shipping cost " + str(prenium_ground_shipping))
else:
print("Drone shipping is cheapest. Drone shipping shipping cost " + str(drone_shipping_cost))

``````

You’re printing the output of functions that don’t `return` anything. Rather than setting the function name equal to a value, `return` the value.

2 Likes

File “script.py”, line 25
def premimum_ground_shipping(weight):
^
SyntaxError: invalid syntax

``````def ground_shipping(weight):
if (weight > 10):
ground_shipping == (weight * 4.75) + 20
elif (weight > 6 and weight <= 10):
ground_shipping == (weight * 4) + 20
elif (weight > 2 and weight <= 6):
ground_shipping == (weight * 3) + 20
else:
ground_shipping == (weight * 1.5) + 20

print(str(ground_shipping(2)))

def drone_shipping_cost(weight):
if (weight > 10):
drone_shipping_cost == weight * 14.25
elif (weight > 6 and weight <= 10):
drone_shipping_cost == weight * 12
elif (weight > 2 and weight <= 6):
drone_shipping_cost == weight * 9
else:
drone_shipping_cost == weight * 4.50

print(str(drone_shipping_cost(9))

def premimum_ground_shipping(weight):
premimum_ground_shipping = weight + 125

print(str(premimum_ground_shipping(5)))

def cheapest(weight):
if (ground_shipping < premimum_ground_shipping and drone_shipping_cost):
print("Ground shpping is the cheapest. Ground shipping cost " + str(ground_shipping))
elif (premimium_ground_shipping < ground_shipping and drone_shipping_cost):
print("Prenium ground shipping is the cheapest. Prenium ground shipping cost " + str(premimum_ground_shipping))
else:
print("Drone shipping is cheapest. Drone shipping shipping cost " + str(drone_shipping_cost))
``````

It would appear you have three opening parenthesis, though only two closing:

``````print(str(drone_shipping_cost(9))
``````

This would cause the next line of code to be read as a SyntaxError.

As for your `None`s @brinbrody is spot on.

2 Likes

Traceback (most recent call last):
File “script.py”, line 37, in
cheapest(17)
File “script.py”, line 26, in cheapest
if (ground_shipping(weight) < premimum_ground_shipping(weight) and ground_shipping(weight) < drone_shipping_cost(weight)):
TypeError: ‘<’ not supported between instances of ‘NoneType’ and ‘NoneType’

``````def ground_shipping(weight):
if (weight > 10):
ground_shipping == (weight * 4.75) + 20
elif (weight > 6 and weight <= 10):
ground_shipping == (weight * 4) + 20
elif (weight > 2 and weight <= 6):
ground_shipping == (weight * 3) + 20
else:
ground_shipping == (weight * 1.5) + 20

def drone_shipping_cost(weight):
if (weight > 10):
drone_shipping_cost == weight * 14.25
elif (weight > 6 and weight <= 10):
drone_shipping_cost == weight * 12
elif (weight > 2 and weight <= 6):
drone_shipping_cost == weight * 9
else:
drone_shipping_cost == weight * 4.50

def premimum_ground_shipping(weight):
premimum_ground_shipping = weight + 125

def cheapest(weight):
if (ground_shipping(weight) < premimum_ground_shipping(weight) and ground_shipping(weight) < drone_shipping_cost(weight)):
print("Ground shpping is the cheapest. Ground shipping cost " + str(ground_shipping))
elif (premimium_ground_shipping(weight) < ground_shipping() and premimium_ground_sipping(weight) < drone_shipping_cost()):
print("Prenium ground shipping is the cheapest. Prenimum ground shipping cost " + str(premimum_ground_shipping()))
else:
print("Drone shipping is cheapest. Drone shipping shipping cost " + str(drone_shipping_cost()))
return ((cheapest(17)))

ground_shipping(2)
drone_shipping_cost(9)
premimum_ground_shipping(5)
cheapest(17)

``````

As stated earlier, your functions have no `return`, so they have a value of `None`.

If we have a function, it can perform calculations. However, without a `return` the results of a calculation are never sent back to where they were called, and they are deleted as soon as the function ends:

``````def add_without_return(n1, n2):
new_number = n1 + n2
#       \
#        new_number will be equal to the result of adding n1 and n2
#        However without a return this value is deleted after the
#        function ends

#  \
#   Prints None

#      new_number is equal to the rsult of adding n1 and n2
#     /
new_number = n1 + n2
return new_number
#   \
#    The return keyword sends a value back to were the function
#    was called

#   \
#    Prints 8
``````

You could also edit the function to simply have:

``````return n1 + n2
``````

Since the variable is being created simply for the purpose of being returned.

Since your functions have no `return`, the value of

``````ground_shipping(weight)
premimum_ground_shipping(weight)
drone_shipping_cost(weight)
``````

will all be equal to `None`, and you cannot compare `None` value to `None` value.

1 Like