10-9. Something of Value


#1

Interpreter keeps giving me "SyntaxError: 'return' outside function" and I have tried to move return to solve the problem but had no luck. Can anyone tell me what is wrong with my codes here?

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]
    print
    
for fruits in prices:
    total = 0
    total = total + prices[key] * stock[key]
    return total
print total

#2

Here is my code and it works;

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 key in prices:

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

print total


#3

Thank you! It worked.
I guess that I had to use the word "key" for my key, and instructions don't even ask for the return anyway.


#4

I tried the above code but I keep getting an error message that says:

"Oops, try again. You should have exactly three print statements! (Make sure there are no occurrences of 'print' in any comment or string!)"

Any suggestions on how to make this work? My code is below...

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 key in prices:
total = total + prices[key] * stock[key]
print total


#5

I guess that you can change capital letters to lowercase in your

print "Price: %s" % prices[key]
print "Stock %s" % stock[key]

I hope that solves your error.