Python class, " a day at supermarket" exercise 11


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/a-day-at-the-supermarket/exercises/making-a-purchase?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>
can not multiply sequence by non-int of type ‘dict’

<What do you expect to happen instead?>
excute correct

```python

shopping_list = [“banana”, “orange”, “apple”]

stock = {
“banana”: 6,
“apple”: 0,
“orange”: 32,
“pear”: 15
}

prices = {
“banana”: 4,
“apple”: 2,
“orange”: 1.5,
“pear”: 3
}

Write your code below!

def compute_bill(food):
total = 0
for item in food:
total += item * prices
return total
print compute_bill(shopping_list)

<do not remove the three backticks above>

#2

total += item * prices

consider what is item and what is prices ?

item is non-int value ("banana", "orange", "apple") and prices is a dictionary. so you are getting that error

Error: can not multiply sequence by non-int of type ‘dict’

Instruction:

For each item in the food list, add the price of that item to total

add this print statement after for loop

for item in food:
  print item

now consider how can you get the prices of every item?


#3

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