13.Allons vérifier!


#1



https://www.codecademy.com/fr/courses/python-beginner-fr-FR-4az90/2/4?curriculum_id=5370f030fed2a866a2000001

je n'ai pas: 1- le bon total,2- le message d'indisponibilité pour l'article qu'il n'y a plus en stock

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

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

def calculer_facture(courses):
    total = 0
    for n in nourriture:
        for c in courses:
            for s in stock:
                if s>=1:
                    for p in prix:
                        total += prix[p]
                        stock[p] -1
                    return total
                else:
                    print '%s indisponible' %s
print calculer_facture(courses)
print stock


l'exercice reste juste -_-


#3

You don't need that many for loops, use for n in food(idk what food is in french but w/e)
then just write an if to check if your stock is bigger than 0
to check it you just do (stock(in french ofcourse)[s] > 0):
then just increment your total with prices[s]
and stock[s] -= 1
then return the total
tell me if you didnt understand why
Just to be clear
you use the [s] to check the value of the key
Hope I helped :smiley:


#4

By the way my friend, What is that list above "courses" I'm just looking at mine and I don't see a second one, is that only in the french version or something?


#5

def calculer_facture(courses):
    total = 0
    for n in nourriture:
        if n>0:
            for n in prix:
                total += prix[n]
                stock[n] -=1
            return total
        else:
            print '%s indisponible' %n

more like that ?


#6

no, if stock[n] > 0
because you want to check the value of the stock,


#7

tell me if you don't understand why I'll try to explain the best way that I can


#9

don't need that, you only need to check if the stock is bigger than 0, just remove it and it should work if you indented properly

and use stock[n] = stock[n] - 1


#10

def calculer_facture(courses):
    total = 0
    for n in nourriture:
        if stock[n] >0 :
            total += prix[n]
            stock[n] = stock[n]-1
            return total
        else:
            print '%s indisponible' %stock[n]

->
4
{'orange': 32, 'banane': 4, 'poire': 15, 'pomme': 0}
None


#11

your return needs to go under the loop like so :

def calculer_facture(courses):
    total = 0
    for n in nourriture:
        if stock[n] >0 :
            total += prix[n]
            stock[n] = stock[n]-1
    return total
        else:
            print '%s indisponible' %stock[n]

#12

that make an error like :
File "python", line 23
else:
^
IndentationError: unexpected indent


#13

You don't need an else,


#14

they didnt say to do anything if it was 0


#16

you need to use for n in food not in price


#17

yea i passed they exercice but i wanna this to be "usable"


#18

what do you want to do with it?


#19

nothing >< but this exercice could be use irl so...
and food or price get the same out put


#20

i don't know why but it's count banana twice...


#21

probably because of this line, instead of price use food(courses)
try removing the 2nd list


#22

the 2nd? courses or nourriture because both are use in calculer_facture :confused:


#23

you arent using nourriture rly the only thing you're using is the courses