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]

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

total = t + total
print t

And I get this as the error

Oops, try again. Your code looks a bit off. Check the Hint if you need help! Your code threw the following error: name 't' is not defined


#2

Can you include your code and your error message?
link: https://www.codecademy.com/en/courses/python-beginner-en-IZ9Ra/1/4?curriculum_id=4f89dab3d788890003000096


#3

#4

click on that box please


#5

According to the instructions, it's pretty self explanatory.
You should add to the code you already have.
First,

Create a variable called total and set it to zero.

total = 0

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.

for key in prices: 
    value = prices[key] * stock[key]
    print value
    total += value

Finally, outside your loop, print total.

print total

All of my indentation is correct. I basically gave you the code, but I tried to explain it. I only did exactly as the instructions asked me, so what part of it was confusing for you?


#6

I got confused when the instructions said
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.


#7

It is also saying that value is not defined


#8

Which part of that specificially?
For each key in prices is psuedocode. It was giving you the instructions for the for loop.
it saying inside of the for each loop, multiply the each value in prices with it's respective value in stock. Also inside of the for each loop, you're supposed to print that.


#9

i edited the my message, it will work now. I made the variable value so that i could add it to total instead of doing total += prices[key] * stock[key]


#10

Again I am getting an error as
File "python", line 21
doing total += stock[key] * prices[key]
^
SyntaxError: invalid syntax


#11

look back at my post that explains the code.
It's all correct there.
i think that you're not completely understanding the lesson, try to read the instructions again and see if you can connect my code with what it's asking.


#12

Oh Yeah Got It!
Thank you so much Kyleaw.
I got the code


#13

alright, no problem!


#14

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