Something of value: correct code


#1

prices = {
"banana" : 4,
"apple" : 2,
"orange" : 1.5,
"pear" : 3,
}

stock = {
"banana" : 6,
"apple" : 0,
"orange" : 32,
"pear" : 15,
}

total = 0
for key in prices:
print key
total += (prices[key]*stock[key])
print total


#2

Is there any error or problem with your code? :hushed:


#3

can you give me the explanation of the code??


#4

You are on the right track, but you need to make minor adjustments!
1- Total + is not a valid syntax. Try removing it .
2- Instead, you need to add total to the product.

Your code should look something like this

total= 0
for key in prices:
    total = (prices[key]*stock[key]) + total
print total

#5

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