Something of value


#1

prices = {
"banana" : 4,
"apple" : 2,
"orange" : 1.5,
"pear" : 3,
}
stock = {
"banana" : 6,
"apple" : 0,
"orange" : 32,
"pear" : 15,
}

for key in prices:
print key
print "price: %s" % prices[key]
print "stock: %s" % stock[key]
for total in prices:
total = 0
market = prices[key] * stock[key]
print market
total += market
print total
what is wrong with that code


#2

What's your error? :slight_smile:


#3

Oops, try again. It looks like your code did not print the correct total.


#4

This should be outside the for loop


#5

And,

you can avoid these three lines

By calculating the total like this,

total += prices[key] * stock[key]


#6

thx a lot bro iam 14 years old too but iam still learning python


#7

Cool, keep at it. :slight_smile:


#8

thanks i hope i will make so many friends


#9

I wish I learned to code when I was 14. Good job! Keep at it. You're never too young to learn valuable skills.


#13