Compute_bill(['apple']) returned 7.5 instead of 2


#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.>
i think it counts too much prices
compute_bill([‘apple’]) returned 7.5 instead of 2
<What do you expect to happen instead?>


def compute_bill(food):
  total=0
  for food in shopping_list:
    total+=prices[food]
    return total

#2

the error message doesn’t reflect the code, which is slightly confusing.

lets add the function call the error message gives:

def compute_bill(food):
  total=0
  for food in shopping_list:
    total+=prices[food]
    return total

# function call
print compute_bill(['apple'])

the function call represents a customer wants buy an apple, but gets charged for everything that is in shopping_list (which is: apple, banana and orange)

we are charging the customer for more then he is buying


#3

The function should acces each item in any food list given, not from shopping_list, and add the item price in total.


#4

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