Beyond "Day at the supermarket"


How do I print a line to tell the user, in the exercise "apple", is out of stock? IOW I would like to print the key for whatever is out of stock: "Sorry, no apples" for example.

Replace this line with your code.


What's stopping you? Sounds like that would be very straight-forward to write.


Well, what is it, genius?


Are you asking for help with some particular problem that you're unable to solve yourself or do you just want it done for you?

You've answered that already, but do you see how that could affect someone's interest in giving you what you ask for?

You're expected to try yourself and if you are unable to do it, then explain what you're missing.


I did try it! That's why I'm asking here, duh! It's not as easy as you think. You have to be able to extract one key and print it. Just the one. No, scratch that, as many keys as point to 0 in stock. Key, I say, not the value, which is easy. So, are you just trolling me or do you have the answer?


How did you get the value if you don't already have the key? I doubt that's the case.


Aaargh! Go away! [padding to fill up char quota]


Well, am I wrong? You probably do have the key since you say that you have the value. So getting the key isn't the problem at all. Where are you actually getting stuck in trying to do this?

Or if you don't have the key, then ask yourself where it's stored and then find out how to get it out of there, and since a dict can hold multiple keys, you'll need to consider which ones it is you want to get out.

Or perhaps you have the key without being aware of it, and you would find it by looking at how you are obtaining the value, which is likely by looking it up using the key.

You can't get anything done if you don't consider what it is you want to do. And you don't seem to be doing that. You're just asking for someone to do it for you. That's not worth anyone's time, including yours. So yes, I will question what you ask for, because you're asking the wrong things, you're asking for things you can do yourself, things you don't need help with except in the sense of somebody just doing it for you. Find out what's stopping you and look that up, or ask about it.


Where in the instructions is this asked for?


Hey, @glyfyxx ,

Why not make this enjoyable for yourself and those who are here to help?

You'll find that if you give an idea a try and then post your code, you'll get a lot more help than you would by just asking for a solution without showing us something you've tried. We all have to put in effort and share it with others to hold a programming community together.

Start with the code that you submitted for Exercise 13: Let's Check Out!, add just a few lines of code that are needed to produce the results you are seeking, and post what you've got. While testing, make sure you call the compute_bill function so that it executes.

There was this song, Yes! We Have No Bananas, from a Broadway show almost a century ago. Two of the lines in the song were ...

Yes, we have no bananas
We have-a no bananas today.

See if you can write your code so that if an item is out of stock, your program outputs lines similar to the above, but specific to the item that is out of stock. If we're out of apples, we'll say ...

Yes, we have no apples
We have-a no apples today.

You already have told the Python interpreter what to do if an item is in stock. Now, tell it what to do if the item is out of stock.


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