Informatique

Question

Bonjour, quelqu'un pourrait m'aider s'il vous plait en informatique . Merci pour votre aide.

Exercice 1 : Écrire une fonction recherche qui prend en paramètres elt un nombre et tab un tableau de nombres, et qui renvoie le tableau des indices de elt dans tab si elt est dans tab et le tableau vide [ ] sinon.

Exemples :

>>> recherche(3, [3, 2, 1, 3, 2, 1] )
[0, 3]
>>> recherche(4, [1, 2, 3])
[ ]

Exercice 2 : Compléter le code ci dessous

resultats = {'Dupont':{'DS1' : [15.5, 4],
'DM1' : [14.5, 1],
'DS2' : [13, 4],
'PROJET1' : [16, 3],
'DS3' : [14, 4]},
'Durand':{'DS1' : [6 , 4],
'DM1' : [14.5, 1],
'DS2' : [8, 4],
'PROJET1' : [9, 3],
'IE1' : [7, 2],
'DS3' : [8, 4],
'DS4' :[15, 4]}}


def moyenne(nom):
if nom in ...:
notes = resultats[nom]
total_points = ...
total_coefficients = ...
for ... in notes.values():
note, coefficient = valeurs
total_points = total_points + ... * coefficient
total_coefficients = ... + coefficient
return round( ... / total_coefficients , 1 )
else:
return -1
Bonjour, quelqu'un pourrait m'aider s'il vous plait en informatique . Merci pour votre aide. Exercice 1 : Écrire une fonction recherche qui prend en paramètres

1 Réponse

  • Réponse :

    Bonsoir,

    Explications :

    def recherche(qui,tableau):

       rep=[]

       for i in range (len(tableau)):

           if tableau[i]==qui:

               rep.append(i)

       return rep

    def moyenne(qui):

       #print ("qui=",qui)    

       if qui in resultats.keys():

           notes = resultats[qui]

           #print ("notes=",notes)

           total_points =0

           total_coefficients = 0

           for donnee in notes.values():

               point, coefficient = donnee

               #print (donnee,point,coefficient)

               total_points += (point* coefficient)

               total_coefficients += coefficient

           return round( total_points / total_coefficients , 1 )

       else:

           return -1

     

     

    resultats={'Dupont':{'DS1':[15.5,4],

                        'DM1':[14.5,1],

                        'DS2':[13,4],

                        'PROJET1':[16,3],

                        'DS3':[14,4]},

              'Durand':{'DS1':[6,4],

                        'DM1':[14.5,1],

                        'DS2':[8,4],

                        'PROJET1':[9,3],

                        'IE1':[7,2],

                        'DS3':[8,4],

                        'DS4':[15,4]}}

    #print (recherche(3,[3,2,1,3,2,1]) )

    #print (recherche(4,[1,2,3]) )

    print (moyenne('Dupont'))    

    print (moyenne('Durand'))    

    print (moyenne('moi'))    

    Image en pièce jointe de la réponse caylus