Sal's Shipping - Type Error

I’m working on the Sal’s Shipping exercise and am getting a TypeError: ‘<’ not supported between instances of ‘float’ and ‘str’ in the final part of the exercise.

My code is:

def cheapest_shipping(weight):
  ground = ground_shipping(weight)
  drone = drone_shipping(weight)
  premium = premium_shipping
  if drone < ground and drone < premium:
    return "Drone shipping is cheapest.  It will cost $" + str(drone)
  elif ground < drone and ground < premium:
    return "Ground shipping is cheapest.  It will cost $" + str(ground)
  else:
    return "Premium shipping is cheapest.  It will cost $" + str(premium)
  
print(cheapest_shipping(4.8))

This brings the error message:
Traceback (most recent call last):
File “script.py”, line 38, in
print(cheapest_shipping(4.8))
File “script.py”, line 33, in cheapest_shipping
elif ground < drone and ground < premium:
TypeError: ‘<’ not supported between instances of ‘float’ and ‘str’

I’ve looked at other solutions and I can’t see what I’m doing wrong.

Hello, @chip2039438995. It appears as though at least one of your values: ground, drone or premium is a string rather than a float. Are you sure that your ground_shipping() and drone_shipping() functions are returning floats? Is premium_shipping a float?

EDIT: I just peeked at your original post prior to your last edit. You assigned premium_shipping as a string with this line: premium_shipping = str(125.0). You want it to be a float. No need to convert the value to a string.

That worked. Thanks!

2 Likes