Help with Sal's Shipping Project

I am working on Sal’s Shipping Project in Learn Python3. I haven’t am seeing the shipping costs printed correctly, but the most expensive is coming out as the cheapest. Here is the code:

link to code: https://gist.github.com/1d2c1e0e48c541cab4f051e11b4a7850

Results:
The cost of ground shipping is $34.4.
The cost of drone shipping is $43.199999999999996.
Drone shipping is cheapest. The cost of drone shipping is $43.199999999999996.

Why would the drone shipping show as the cheaper option? Thank you!

Hi @cheytheresa, and welcome to the Codecademy Forums!

What types of values are returned by your cost_ground_shipping and cost_drone_shipping functions? Are they numbers or something other than that? How are values of this type compared?

Edited on February 1, 2020 to add the following:

Link to project: Sal’s Shipping

Your code would be easier to read if it were formatted correctly for posting. See How to ask good questions (and get good answers).

Hi @appylpye! I included a link to the code in my original post, as copying and pasting resulted in poor formatting.

cost_ground_shipping and cost_drone_shipping result functions in cost values, but I have them as str(). Sample results:

cost_ground_shipping function result: The cost of ground shipping is $34.4.
cost_drone_shipping function result: The cost of drone shipping is $43.199999999999996.

Thanks!

Note this comparison of the strings:

>>> "The cost of ground shipping is $34.4." < "The cost of drone shipping is $43.199999999999996."
False

Look for the first characters where the strings begin to differ, and compare them. This explains the problem.

As a remedy, you could have the cost_ground_shipping and cost_drone_shipping functions return numbers. Then you could perform the comparison and report the results within the cheapest_shipping function.

2 Likes

Thank you, @appylpye!

Here is my updated code: https://gist.github.com/6ae9dd91bc73a1df63b8ccbce8923fa4

Your suggestion fixed the issue, and I was then able to add the premium shipping option and no longer the got the TypeError I was getting for premium as I was previously regarding int, float, str. I now get accurate results for all of the tests:

Results:
The cost of ground shipping is $34.4.
The cost of drone shipping is $43.199999999999996.
Ground shipping is cheapest. The cost of ground shipping is $34.4.

Thank you so much for your help!

2 Likes

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.