After fiddling around with the code I figured out the answer but I’m confused as to how that answer is correct.
Here are the directions: Let's determine how much money you would make if you sold all of your food. 1.Create a variable called total and set it to zero. 2.Loop through the prices dictionaries. 3.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. 4.Finally, outside your loop, print total.
Here is my answer: 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 total in prices:
prices = 4 * 6
print prices`
Even though I didnt print out the total price for all the variables, it said that i was correct. If somebody could explain me how this is correct and how i can fix it. In the hints it said You should print the number all by itself—no need for any additional text!
Does it want me to multiply each value/number individually? Isn’t there a way to make this easier?
Please help me understand this part. Thank you guys.
I keep getting this error on this line of code. Oops, try again. compute_bill([‘apple’]) resulted in a TypeError: unsupported operand type(s) for +: ‘int’ and 'str’
Here is the code: def compute_bill(food): total = 0 for item in food: total += item return total
could it have something to do with the fact that the price of apple is 2 and there is 0 left in stock so when the system multiplies the two number it gets zero?
no joke that actually made me feel better and even though i may get stuck basically on every exercise i’m gonna keep learning. Thank you very much for your words of kindness.
Seriously, I learn more when I make a mistake than when I get it right the first time. That way you know more about what to watch for in future errors.