A Day at The SuperMarket


#1



https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/1/4?curriculum_id=4f89dab3d788890003000096#


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

INSTRUCTIONS:

Create a variable called total and set it to zero.Loop through the prices dictionaries.For each key in prices, multiply the number in prices by the number in stock. Print that value into the console and then add it to total.Finally, outside your loop, print total.

I am sure its because im tired as all get out and he obv anser is right in front of me just looking for a little direction in the right area! :smiley:

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

tHIS IS THE OUTPUT::
orange
price: 1.5
stock: 32
pear
price: 3
stock: 15
banana
price: 4
stock: 6
apple
price: 2
stock: 0
48.0
45
24
0
0
None


#2

All of your code is right except for in your second for loop, you never set total equal to prices times the stock

just add this statement to your second for loop:

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


#3

Lol duh i knew it was something silly thanks so much!


#4

No problem glad to help


#5

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