0% found this document useful (0 votes)
15 views4 pages

DC2 2023 Correction

This document contains a correction for a computer science exam at the Institut Préparatoire aux Études d'Ingénieurs de Gabés, detailing exercises on numpy and mathematical functions. It includes various programming tasks such as matrix operations, data input/output, and sorting algorithms. The document is structured into exercises with specific questions and coding requirements, aimed at assessing students' understanding of the material.

Uploaded by

karimchgara1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

DC2 2023 Correction

This document contains a correction for a computer science exam at the Institut Préparatoire aux Études d'Ingénieurs de Gabés, detailing exercises on numpy and mathematical functions. It includes various programming tasks such as matrix operations, data input/output, and sorting algorithms. The document is structured into exercises with specific questions and coding requirements, aimed at assessing students' understanding of the material.

Uploaded by

karimchgara1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Ministère de l’Enseignement Supérieur et de la Recherche Scientifique

Institut Préparatoire aux Études d'Ingénieurs de Gabés

DC2 Correction
Matière: Informatique (MP1 - PC1 - T1 et BG1) Durée : 2H AU: 2022/2023
Enseignantes : BENFRADJ A., HACHAICHI H. & MEFTEH F. Nombre des pages : 4

Exercice 1 (8 questions *0.5pt=4 pts):


I.
1. import numpy as np
A=np.array([[-3,0,1,3],[5,2,0,0],[1,1,1,1],[0,-1,2,-2]])

2. import numpy.linalg as npl


npl.det(A)

3. TA=np.transpose(A))

4. np.trace(A)

5. D,V=npl.eig(A)

II.
1. from math import *
fct=lambda x:exp(-x**x+3*x)

2. def Points():
f=open("Abscisses.txt" ,'r')
Lx=f.readlines()
print(Lx)
for i in range(len(Lx)):
Lx[i]=float(Lx[i].strip())
Ly=[fct(x) for x in Lx]
return Lx,Ly

3. import matplotlib.pyplot as plt


def Courbe(Lx,Ly):
plt.plot(Lx,Ly,color='b', linestyle=':')
plt.show()
Exercice 2 (6 questions*1pt=6 pts):
1. def Taille():
while True:
n=int(input('donner un entier 2 et 20'))
if n in range(2,21):
break
return n
2. def Saisie_Tab(N):
M=np.ones((N,N))
for i in range(N):

1
for j in range (N):
while True:
a=int(input('donner un entier positif'))
if a>0:
break
M[i,j]=a
return M

3. def Som_lig(M,i) :
L=M[i,:].tolist()
return sum(L)

4. def liste_som(M) :
L=[]
n=len(M)
for i in range(n):
L.append(Som_lig(M,i))
return L

5. def tri_bulle(L):
n = len(L)
for i in range(n):
for j in range(0, n-i-1):
if L[j] > L[j+1] :
L[j], L[j+1] = L[j+1], L[j]
return L
def tri_insertion(L):
for i in range(1, len(L)):
k = L[i]
j = i-1
while j >= 0 and k < L[j] :
L[j + 1] = L[j]
j -= 1
L[j + 1] = k
return L

def tri_selection(L):
for i in range(len(L)):
min = i
for j in range(i+1, len(L)):
if L[min] > L[j]:
min = j
tmp = L[i]
L[i] = L[min]
L[min] = tmp
return( L)

2
6. N=Taille()
M=Saisie_Tab(N)
L=liste_som(M)
print(tri_list(L))

Problème (7 questions*1.5 pt=10.5 pts)


1. def saisir(N):
f=open("Banques.txt","w")
for i in range(N):
CODE=input("taper le code")
NOM=input("taper le nom ")
PRENOM=input("taper le prénom ")
SOL=input("taper le solde")
f.write(Code+" "+NOM+" "+PRENOM+" "+SOL+"\n")
f.close()

2. def Dic_comptes (fich) :


f=open(fich,"r")
L=f.readlines()
f.close()
D={}
for l in L:
l=l.strip().split()
D[int(l[0])]=[l[1],l[2],int(l[3])]
return D

3. def Depot(D, cd, s) :


for cle in D:
if cle==cd:
D[cle][2]+=s
return D

4. def Retrait(D, cd, s) :


for cle in D:
if cle==cd:
D[cle][2]-=s
return D

5. def Chercher_client(D,cd) :
if cd in D:
l=D[cd]
print (l[0], ' ', l[1],' ',l[2])
else:
return None

6. def Chercher_sup(D) :
sol=0
L=[]
3
for cle in D:
if D[cle][2]>sol:
sol=D[cle][2]
cd=cle
L=D[cle]
return cd, L

7. def TrierFich(D):
f=open('tri.txt','w')
while (len(D)!=0):
cd, L=Chercher_sup(D)
f.write(L[0]+ ' '+ L[1]+' '+str(L[2])+'\n')
del(D[cd])
f.close()

You might also like