11 making a purchase


hello here is my code which seem correct to me but i "ve got an error message saying : oops try again your code doesn"t work for 'pomme' it returns 4 instead of 2 . i can't find where i've mistaken please give me some help

courses = ["banane", "orange", "pomme"]

stock = { "banane": 6,
    "pomme": 0,
    "orange": 32,
    "poire": 15
prix = { "banane": 4,
    "pomme": 2,
    "orange": 1.5,
    "poire": 3

# Ecrivez votre code ci-dessous :
def calculer_facture (nourriture):
    total = 0
    for nourriture in courses:
        total +=prix[nourriture]
        return total
    print calculer_facture


a function ends the moment a return keyword is reached, which in your case is happening in the first run of the loop. You might want to change the indention of return so the whole loop can run


i 've tried it but the error message says that the code return 7.5 instead of 2


do you have the url exercise? This is not the english course


here is the url and it"s a french course


never mind, i already see the problem. it is in your for loop:

for nourriture in courses:

you shouldn't loop over courses (your fixed list at line 1), you should loop over nourriture, the exercise calls your function with different list (by passing a list as argument), so you should loop over the function parameter (nourriture) instead


that works fine now thanks for helping and make me understand my mistake


Write your code below!
def compute_bill(food):
for item in food:
total= total+prices[item]
return total

need=["apple", "banana"]
print compute_bill(need)


It is not the correct code


It is not working this


it is work with me !


How is working this code?



Guys, it is against the guidelines to post answers, if you need help please create a new topic so someone can help you