Sal's Shipping TypeError Help

https://www.codecademy.com/courses/learn-python-3/projects/sals-shipping

After trying different ways, this is the code that I ended up with (https://gist.github.com/225c34883e2d9dafb8be73e046cb1a6e):

def cost_ground(weight):
if weight<=2:
price=1.5
elif weight>=2 and weight<=6:
price=3
elif weight>=6 and weight<=10:
price=4
else:
price=4.75
return 20+(price*weight)
print(cost_ground(8.4))

cost_premium=125

def cost_drone(weight):
if weight<=2:
price=4.5
elif weight>=2 and weight<=6:
price=9
elif weight>=6 and weight<=10:
price=12
else:
price=14.25
return (price*weight)
print(cost_drone(1.5))

def best_price(weight):
ground=cost_ground
premium=cost_premium
drone=cost_drone

if ground < drone and ground < premium:
return “Ground Shipping is cheapest and will cost you”+str(cost_ground)
elif premium < ground and premium < drone:
return “Premium Ground Shipping is cheapest and will cost you”+cost_premium
else:
return “Drone Shipping is cheapest and it will cost you” +str(cost_drone)

best_price(4.8)
best_price(41.5)

Here is the message that I am getting, with the TypeError at the end:
53.6
6.75
Traceback (most recent call last):
File “script.py”, line 39, in
best_price(4.8)
File “script.py”, line 32, in best_price
if ground < drone and ground < premium:
TypeError: ‘<’ not supported between instances of ‘function’ and ‘function’

Please help, I tried to rewrite it several times. I tried to copy the code from the walkthrough but I got a NameError message for method and code saying that they are not defined. I am new at this.
Thank you!

Do you agree that this is indeed not supported and that this should crash?

Did you mean to do that?
What did you mean?

Now you have some kind of difference between reality and what you meant. How would you adjust reality?

If you have one thing that you did not mean, then, where did you get it from? Is its definition wrong, or did you mean to use something else?


Stop trying to copy better and instead consider what should happen and observe what is happening. That’ll tell you what to change.

2 Likes

You’ve got a location for where this happens.

You’re using < so you’re looking to test whether one thing is smaller than another.

What is smaller than what?

Maybe those would be numbers. Which numbers, and where are they supposed to come from. What’s involved in obtaining them? That’s a bunch of actions that you can continue making observations for.

You’re also told that you’re comparing two functions. That’s probably not an operation you would want to do with a function. Is that a function that you did mean to use in some way? What operations does a function support, what can you do with a function?

1 Like

Thank you for answering ionatan!
For the moment I can’t say whether I agree or not since I am really new at this. I saw what you are referring to and I though that I corrected it but I ended up with a mistake. It would be great if you could take a look at it!

def cost_ground(weight):
if weight<=2:
price=1.5
elif weight>=2 and weight<=6:
price=3
elif weight>=6 and weight<=10:
price=4
else:
price=4.75
return 20+(price*weight)
print(cost_ground(8.4))

cost_premium=125

def cost_drone(weight):
if weight<=2:
price=4.5
elif weight>=2 and weight<=6:
price=9
elif weight>=6 and weight<=10:
price=12
else:
price=14.25
return (price*weight)
print(cost_drone(1.5))

def best_price(weight):
ground=cost_ground(weight)
premium=cost_premium
drone=cost_drone(weight)

if ground < drone and ground < premium:
return "Ground Shipping is cheapest and will cost you "+str(cost_ground)
elif premium < ground and premium < drone:
return "Premium Ground Shipping is cheapest and will cost you "+str(cost_premium)
else:
return "Drone Shipping is cheapest and it will cost you " +str(cost_drone)

best_price(4.8)
best_price(41.5)

print(best_price(4.8))
print(best_price(41.5))

And now there is no error but the number is wrong:
53.6
6.75
Ground Shipping is cheapest and will cost you <function cost_ground at 0x7f86cb767d08>
Premium Ground Shipping is cheapest and will cost you 125

Thank you so much for your help! I am learning

Actually, you can.

Did you mean to compare two functions? Is that something you meant to do?

As soon as you see something that you don’t know whether it can be done then that’s a bug - you’re writing your program in terms of things that you know can be done. You can’t leave anything in there that you don’t fully control. Either learn it or remove it. Considering what you meant will tell you that this is not what you meant so you would remove it. If it’s something you meant but don’t fully understand, then you’d go learn it so you’re able to leverage it.

1 Like

Fair enough: I saw that I equalled
ground=cost_ground
premium=cost_premium
drone=cost_drone

when I should have done
ground=cost_ground(weight)
premium=cost_premium
drone=cost_drone(weight)

and it worked for the second print(best_price(41.5))
thank you for your help!