Python Project Sal's Shipping

Hi. Can someone explain to me why my code for task 6 in this project isn’t producing the expected output?

Hello @wanguimaina1910, can you post your code please?

Here it is:

def ground_shipping(weight):

  if weight <= 2:

    return weight *1.50 + 20.00

  elif weight <= 6:

   return weight * 3.00 + 20.00

  elif weight <= 10:

    return weight * 4.00+ 20.00


    return weight ** 4.75 + 20.00

print (ground_shipping(8.4))

premium_ground_shipping = 125.00

def drone_shipping(weight):

  if weight <= 2:

    return weight * 4.50 + 0.00

  elif weight <= 6:

   return weight * 9.00 + 0.00

  elif weight <= 10:

    return weight * 12.00 + 0.00


    return weight ** 14.25 + 0.00


print (drone_shipping(1.5))

def cheapest_method(weight):


  if ground_shipping(weight) < drone_shipping(weight)and ground_shipping (weight)< premium_ground_shipping:

    return ground_shipping(weight)

  elif drone_shipping(weight) < ground_shipping(weight) and drone_shipping(weight)  < premium_ground_shipping:

    return drone_shipping(weight) 


    return premium_ground_shipping

print (cheapest_method (17))

Hello @wanguimaina1910. When I write the code the way you do, I get an error TypeError: '<' not supported between instances of function and float. If you are getting the same error, then that means you might have to compare the prices a different way.

Hint if you're stuck

Maybe use variables.

#just one example:
def calc_cost(weight):
  drone = drone_shipping_cost(weight)
#Then compare the variables with each other (store the other function in a variable too).

I hope this helps!

P.S. When you post code, press this button:

Then put the code between the back ticks:
Screen Shot 2020-05-02 at 14.06.13

1 Like

I have fixed the code formatting for you. Whitespace is critical in Python, and properly formatted code makes it much easier for us to help you @wanguimaina1910 :slight_smile:

I don’t get that error if I run the code in a REPL.

Your program isn’t behaving in the way you’re expecting, and is not producing the output described by the task, because you simply haven’t told it to.

The task:

Using those two functions for ground shipping cost and drone shipping cost, as well as the cost of premium ground shipping, write a function that takes one parameter, weight and prints a statement that tells the user

  • The shipping method that is cheapest.
  • How much it would cost to ship a package of said weight using this method.

I have added the emphasis to the quote above.

Your cheapest_method function contains exactly 0 calls to the print() function… so it’s doing exactly what you told it to do, and not printing anything.

What you’re doing instead is printing the return value of the function on the last line of your program, which you could use to produce the requested output with a slight modification to your function. :slight_smile:

1 Like