An iteration with for
in a dictionary always iterates only over the keys - so you did not see the values.
Dictionaries, however, in addition to being directly iterated, have three methods that return specialized iterators: on the keys ( .keys()
), on the values ( .values()
) or on both ( .items()
) - the latter method returns the keys and sequence values of two items (tuples) - and can be used with the augmented Python assignemnt that allows multiple variables to receive the item values of a sequence.
So you can do it like this:
lanchonete = {"Salgado":4.50, "Lanche":6.50,"Suco":3.00,"Refrigerante":3.50,"Doce":1.00}
for produto, preco in lanchonete.items():
print(produto, preco)
If you want to add more definitions to what you are printing, a good request is the f-strings, which exist from Python 3.6:
for produto, preco in lanchonete.items():
print(f"Produto {produto}: R${preco:0.02f}")