I need to multiply the values from each key and then add all the values together to print a single number. I know this probably super simple but i'm stuck
In my mind, I'd address this with something like:
for v in prices:
total = sum(v * (v in stock))
print total
But something like that isn't going to work :)
prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3 }
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15 }
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…