''' ################################################################# ############ Correction de l'examen n°1 Décembre 2022########### ################################################################# # Probleme ''' def SaisieLogiciel(): lo={} while True: lo['Designation']=input('donner designation') lo['Licence']=input('donner licence') lo['Editeur']=input('donner editeur') lo['AnneEdition']=int(input('donner AnneEdition')) lo['Version']=input('donner Version') lo['TailleDisque']=int(input('donner Taille disque')) if len(lo['Designation'])<=20 and lo['Licence'] in 'cClLpP': break return lo def AjoutLogiciel(L,X): L.append(X) return L def ListLogicielParEditeur(L,e): #Ed=[l for l in L if l['Editeur']==e] Ed=[] for l in L: if l['Editeur']==e:Ed.append(l) return tuple(Ed) def EspaceTotalOccupe(L): return sum([l[taille] for l in L]) def rechercheLogiciel(L,d): r=[L.index(l) for l in L if l['Designation']==d] if len(r)>0:return r[0] return -1 def NombreLogicielCommercial(L): return len([1 for l in L if l['Licence'] in 'cC']) # Part2 def EspaceOccupe(O): return EspaceTotalOccupe(O['LogInst']) def InstallerLogiciel(O,X): el=O['CapaciteDisque']-EspaceOccupe(O) if el>X['TailleDisque'] and X not in O['LogInst']: O['LogInst'].append(X) def DesinstallerLogiciel(O,d): idx=RechercheLogiciel(O['LogInst'],d) #O['LogInst'].remove(O['LogInst'][idx]) O['LogInst'].pop(idx) def VideOrdinateur(O): O['LogInst'].clear() #O['LogInst']=[] #Part 3 def QjouterOrdinateur(O,LO): LO.insert(0,O) #[O]+LO def SupprimerOrdinateur(LO,N): for o in LO: if o['num']==N: idx=LO.index(o) LO.pop(idx) def FormaterOrdinateur(LO,N): for o in LO: if o['num']==N: ViderOrdinateur(o) # Exercice # Question 1 def enfant(F,p): return F.get(p , set()) # Question 2 def ens_enfant(F,X): S=set() for p in X : S= S| enfant(F,p) return S # Question 3 def petit_enfant(F, p): return ens_enfant(F,enfant(F,p)) # Question 4 def parent(F,p): return {x for x in F if p in enfant(F,x)} # Question 5 def freres_soeurs(F,p): return ens_enfant(F,parent(F,p)) - {p} # Question 6 def neveux_nieces(F, p): return ens_enfant(F, freres_soeurs(F,p)) # Question 7. def oncles_tantes(F,p): S=set() for x in parent(F,p) : S = S | freres_soeurs(F,x) return S