Sal's shipping "TypeError" "nonetype"

Traceback (most recent call last):
File “script.py”, line 43, in
best_price(2)
File “script.py”, line 35, in best_price
if ground < drone and ground < premium:
TypeError: ‘<’ not supported between instances of ‘NoneType’ and ‘NoneType’

This is error I keep receiving any thoughts?

Hello @matty2fatty, welcome to the forums! The print() function effectively returns None. Which means, in the drone_ship and ground_ship functions, like here:

  return print(price * weight)

You’re effectively returning None. You can’t use comparison operators like < or > with None:

None > None
#throws an error
3 > None
#throws an error
None > 3
#throws an error
2 Likes

Thanks so much @codeneutrino, lol I actually was about to post that I was pretty sure that was the solution cause I got it to work finally. but I have new question … to make the last function work why do I need to put the str() for the values in the final function like so…

https://gist.github.com/083f5478286e99d33fde9021cfecd1a3

thanks again and you’re awesome!!!

It’s because you have line like the following "This is a string" + name. The + is used to combine two items (in this case you want to add to the end of your string, right?) but what is the code supposed to do when the second item is not a string (like in your example). You’ll get type errors since you’re trying to combine two different data types. If you use str() beforehand you convert the other variable to a string and therefore the concatenation is straightforward.

A neat alternative to this, if you’re calling str() all the time just to print is to use string formatting instead-

2 Likes