If any shipping methods are equal, would the arguements fall apart? I’m not sure if I have articulated that well but in the syntax, we only specified if one cost was < another cost, but what happens when one method is equal to another method.
Eg. what if ground_shipping = premium_ground_shipping < drone_shipping
Wouldn’t that return drone shipping as the preferred shipping method because it is covered by the ‘Else’ statement?
I’m sure that this specific scenario doesn’t occur or it might not even be possible to occur in this task but shouldn’t we try to cover all of our bases anyway?
Why not try it out for yourself? Set ground and premium to the same value (that’s also less than drone) and see what happens! You’re correct, drone would be the cost returned. What changes could you make to the code to return ground or premium instead?
Asides from that, there are two other things I’d like to point out in your code. Firstly, you’re missing a return statement that will return method and cost.
Secondly, you’ve got a typo on the following line (should be cost and not costs).
Thank you so much for such a quick and helpful response @victoria_dr.
It did take a little head scratching to get ground and premium to equal which I did try to resolve before raising the question. I attempted to solve this by iteratively changing the value of cheapest_shipping(weight) so that it was $125 for both ground and premium but I don’t think this worked.
After your response I commented out a few lines of code and just changed the ground_shipping function to a variable that was also equal to 125. Do you think that was the most efficient way to check? I thought the numerous lines of commenting out looked a bit messy and might get confusing. I also just learnt that you can’t comment out multiple lines in python which is a bit annoying.
Sorry, I forgot to address the main issue I raised. Is it as simple as adding <= in the cheapest_shipping functions if, elif, else statement?
I have just been trying to figure out all of the possible scenarios where different methods might equal or be smaller than each other and it sort of made my head spin a bit. Hopefully the answer is that simple and I just overthought it.
In future posts with code, please format it using the </> button.
Why did you set ground to 125? This doesn’t solve the issue that if ground == premium, drone would be returned. It just makes it more obvious that there’s an issue. Walk step-by-step through your code if both ground and premium were 125 and drone was more than 125. Rather than returning ground or premium, drone would still be returned.
Have you tried this out for yourself? Run your code with this implemented and see if it works. Yes, it’s as simple as using <= rather than <!
You can surround your code with triple quotation marks (""") on both ends. This is effectively a multi-line string, but one that isn’t assigned to any variable, used in a function, etc. It acts like a multi-line comment.
To explain why I tried to set ground to 125, it was my attempt to break the code and to test if the arguments fell apart which they did.
I’m not sure why I got so confused about all of this.
I did alter the code to include the = sign and it held up to my arguments but I wasn’t sure if I was missing something.
Also, I did already learn that you can use “”" to comment out multiple lines but I had somehow forgotten as i’m dabbling in a few languages. I did a quick google search and thought I saw it said somewhere that you can’t comment out multiple lines in Python.
Again, I cannot thank you enough for your patience, help and guidance.
Just to add this into the mix (as @victoria_dr mentioned):
While using """ to comment out multiple lines works fine, it is technically not a comment-it is a way to have a string over multiple lines. For example:
Ahh, i’m with you now. I have just played around with it a little including setting a string over multiple lines and then trying to comment that out but actually as you said, it isn’t possible to comment out multiple lines in Python. Still, at least it helps. Thanks for the additional insight @codeneutrino. That’s really helpful.
As I say, I have definitely learnt this already but as i’m new to coding and trying to tackle a few languages, it’s a pretty steep learning curve and not everything is quite sticking all of the time yet.