0% found this document useful (0 votes)
34 views

Code2pdf 6564f797c624e

The document contains definitions for 10 functions in Python with comments labeling each one. The functions cover a range of tasks including filtering lists, calculating polynomials, generating lists of combinations, playing a guessing game, analyzing student grades, calculating the Fibonacci sequence, set operations, merging sorted lists, checking if a list is sorted, and calculating statistics of lists.

Uploaded by

zakariaramiz2205
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)
34 views

Code2pdf 6564f797c624e

The document contains definitions for 10 functions in Python with comments labeling each one. The functions cover a range of tasks including filtering lists, calculating polynomials, generating lists of combinations, playing a guessing game, analyzing student grades, calculating the Fibonacci sequence, set operations, merging sorted lists, checking if a list is sorted, and calculating statistics of lists.

Uploaded by

zakariaramiz2205
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/ 2

#Ex1

def seuil(L,s):
l=[]
for i in range(len(L)):
if L[i] <= s:
l+=[L[i]]
return l

#Ex2
def poly(C,D,x):
v=0
for i in range(len(C)):
v+=(x**(D[min(len(D)-1,i)]))*C[i]
return v

#Ex3
def lstcr():
a="abc"
b="de"
c=""
l=[]
for i in range(3):
c+=a[i]
for y in range(2):
c+=b[y]
l+=[c]
c=c[0:1]
c=""
return l

#Ex4
from random import *
def jeu():
x=randint(1,100)
print("Donnez un nombre entre 1 et 100:")
l=[]
while(True):
a=int(input())
l+=[a]
if a < x:
print("Trop petit!")
elif a > x:
print("Trop grand!")
else:
print("Correct!")
break
print(f"Nombres de tentatives: {len(l)}\nNombres proposés:")
return l

#Ex5
def etudiants(E,N):
max=0
min=0
inf=[]
moyenne=0
for i in range(len(N)):
if N[i] > N[max]:
max=i
elif N[i] < N[min]:
min=i
moyenne+=N[i]
moyenne/=len(N)
for i in range(len(N)):
if N[i] < moyenne:
inf+=[E[i]]
print(f"Meilleure Note: {N[max]} de {E[max]}\nLa plus mauvaise Note: {N[min]} de {E[min]}\nEtudiants ayant des notes au dessous de la moyenne:\n{inf}")

#Ex6
def fibonacci(m):
a=1
b=1
c=0
l=[a,b]
while(b<=m):
c=b
b+=a
a=c
l+=[b]
if m >= 2:
l=l[:len(l)-1]
return l

#Ex7
#1
def union(L1,L2):
L=L1+L2
for i in range(len(L)):
y=i+1
while(y<len(L)):
if L[y]==L[i]:
L[y]=[]
y+=1
while([] in L):
L.remove([])
return L

#2
def intersection(L1,L2):
L=[]
for a in L1:
for b in L2:
if a == b:
L+=[a]
break
return L

#3
def isEnsemble(L):
for a in L:
L.remove(a)
for b in L:
if a == b:
return False
return True

#4
def isInEnsemble(L,x):
for a in L:
if a == x:
return True
return False

#Ex8
def fusion(A,B):
i=0
y=0
l=[]
while(True):
a=min(A[i],B[y])
l+=[a]
if a == A[i]:
i+=1
elif a == B[y]:
y+=1
if i == len(A):
l+=B[y:]
break
elif y == len(B):
l+=A[i:]
break
return l

#Ex9
def trie(L):
a=L[0]
for b in L:
if b >= a:
a=b
else:
return False
return True

#Ex10
def statistique(L):
val=[]
eff=[]
for a in L:
val+=[a]
i=0
for b in L:
if b == a:
i+=1
eff+=[i]
while(a in L):
L.remove(a)
min=0
max=0
moyenne=0
moyenne2=0
for i in range(len(val)):
if val[i] > val[max]:
max=i
elif val[i] < val[min]:
min=i
moyenne+=val[i]
moyenne2+=val[i]**2
moyenne/=len(val)
moyenne2/=len(val)
etendu=val[max]-val[min]
max=0
for i in range(len(eff)):
if eff[i] > eff[max]:
max=i
mode=val[max]
ecartType=moyenne2-moyenne**2

You might also like