What does TypeError: unorderable types: function() < float() mean?

I am working on: https://www.codecademy.com/courses/learn-python-3/projects/sals-shipping

So I wrote this:

  if weight <= 2:
    price_per_pound = 4.50
  elif weight <= 6:
    price_per_pound = 9.00
  elif weight <= 10:
    price_per_pound = 12.00
  else:
    price_per_pound = 14.25
  return weight * price_per_pound

print(shipping_cost_drone(1.5))

def print_cheapest_shipping_method(weight):
  ground = shipping_cost_ground 
  premium = shipping_cost_premium
  drone = shipping_cost_drone

It is basically saying what different shipping options are and how much they cost. The functions are not important for my question.

I needed to find the cheapest option depending on what the customer chooses as (weight). I wrote this:

if ground < premium and ground < drone:
    method = "standard ground"
    cost = ground
  
  if premium < ground and premium < drone:
    method = "premium ground"
    cost = premium
    
  if drone < ground and drone < premium:
    method = "drone"
    cost = drone
  
  print("The cheapest option available is $%.2f with %s shipping."
       % (cost, method)
       ) 

After I try to print some results and test it out, it tells me

Traceback (most recent call last):
File “script.py”, line 51, in
print_cheapest_shipping_method(4.8)
File “script.py”, line 35, in print_cheapest_shipping_method
if ground < premium and ground < drone:
TypeError: unorderable types: function() < float()

I don’t understand what the error is telling me. The tutorial video did the same thing and it worked for them. What am I doing wrong?

That’s not a meaningful comparison.

Is a helicopter less than water? uhh. TypeError.

Try comparing numbers instead. Those are meaningfully compared that way.

import sys
sys < 5  # don't compare these two, doesn't make sense, they're of completely different kinds

Hey! Having same issue! So glad it’s not just me :slight_smile: Did you find a solution?

Did anyone find a solution to this? I understand why it gave an error, but don’t understand why he didn’t get one in the video.

The problem is that the original poster, bardiacodes, coded his function like this:

def print_cheapest_shipping_method(weight):
  ground = shipping_cost_ground 
  premium = shipping_cost_premium
  drone = shipping_cost_drone

… and then later on, had some ‘if’ statements similar to this:

if ground < premium and ground < drone:

Now, shipping_cost_ground, and shipping_cost_drone are functions.
(shipping_cost_premium is a float.) A statement like

ground = shipping_cost_ground 

assigns the function shipping_cost_ground itself to the alias ground. It is a conventional assignment statement. From that moment forward, Python considers ground to be indistinguishable from and interchangeable with the function shipping_cost_ground.

That’s why the error message complained that ground < premium was trying to compare

unorderable types: function() < float()

What the OP meant, or was trying to do was something like:

ground = shipping_cost_ground(weight)

… where weight is a number.

See the difference? It’s the parentheses! In the assignment statement, there are no parentheses, and in the properly-formatted function call, there are parentheses, within which is the argument.

Here’s why:
capture