That’s all fair enough.
As you can see, there’s a couple of solutions here and maybe you can follow the code, and maybe not.
Generally speaking, flat is better than nested. So, if you don’t need to nest, then it’s possibly better not to.
That said, there are times when nesting is a cleaner solution, but think about your data structure: "product", 2.99
, that’s a Tuple, right? That can be unpacked with item, price = ("product", 2.99)
from which either or both can be displayed with the print()
function.
You can can now have a dictionary of Tuples, which is less hassle to access; I’d make it function, like this:
def menu(key):
items = {
1: ("Ham & Cheese", 5),
2: ("Cheesy Garlic", 5),
3: ("Hawaiian", 5),
4: ("Classic Cheese", 5)
}
return items.get(key)
… which can be accessed with name, price = menu(key)
which in turn can be looped:
for key in range(1,5):
name, price = menu(key)
print(name, price)
Once you’re that far, and it’s doing what you want, you can get a little creative with the print()
function within that loop and have something like this: print(f"{key}: {name.ljust(18,'.')}${price:0.2f}")
which can look a little intimidating, but is not hard to pull apart, which would be a good thing for you to do, so that you expand on what you’ve already learned.