I don't feel like I solve the problem


#1



9. Something of value


So I've been working on this problem for a while and I could not figure it out. Finally I came up with the code below and it said I got it. However, I do not feel that truly solve the problem and that the code I wrote somehow tricked the system into letting me pass. Could someone look over the code for this excessive and let me know if my code is what I was supposed to input?


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]


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


#2

This segment of code looks like it is inside the for block. Remove the indentation. The print statement should not be inside its for loop.

total = 0
for x in prices:
    total += prices[x] * stock[x]
print total

#3

Okay, thank you.Still feels like a fluke though.


#4

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