11 making a purchase


#1

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

#2

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


#3

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


#4

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


#5

here is the url and it"s a french course
https://www.codecademy.com/fr/courses/python-beginner-fr-FR-4az90/2/2?curriculum_id=5370f030fed2a866a2000001#


#6

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


#7

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


#8

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

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


#9

It is not the correct code


#10

It is not working this


#11

it is work with me !


#12

How is working this code?


#13


#14

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