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:
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?
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.
>>> "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.
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.