DS INFO 1TSI2 ADOCH

Telechargé par Youness Ztati
# Correction DS N° 1 Trimestre 2 1TSI2 : date 13 Février 2020 M. ADOCH
from random import randint
#Question 1
jour = 31
heur = 24
mois = 12
tab_temp = [[0]*heur]*jour
#print(tab_temp)
for i in range(jour):
for j in range(heur):
tab_temp[i][j] = randint(0,50)
#print(tab_temp)
#Question 2
jr = 1
def max_temp(jr):
tmp_max_jr = tab_temp[jr][0]
for i in range(1,heur):
if tmp_max_jr < tab_temp[jr][i]:
max = tab_temp[jr][i]
return tmp_max_jr
#print("la température maximal au jour:",jr,"est :",max_temp(1))
#Q3
def nb_jours_glacials():
nbr_jr_glacial = 0
for jr in range(jour):
if max_temp(jr) < 10 :
nbr_jr_glacial += 1
return nbr_jr_glacial
#print(nb_jours_glacials())
#Q4
jr = 5
def temp_moyenne_journee(jr):
som = 0
for hr in range(8,19):
som = som + tab_temp[jr][hr]
return (som/(11))
#print(temp_moyenne_journee(jr))
#Q5
tab_temp_2019 = [[[0]*heur]*jour]*mois
for m in range(mois):
for j in range(jour):
for h in range(heur):
tab_temp_2019[m][j][h] = randint(0,50)
def temp_moy_journée(jr,month):
som = 0
for h in range(8,19):
som = som + tab_temp_2019[month][jr][h]
return (som/11)
#print(temp_moy_journée(jr=5,month=2))
#Q6
def afficher_moyenne_mars():
for j in range(31):
print(j,'/',3,'/',2019,':',temp_moy_journée(j,3))
#print(afficher_moyenne_mars())
#---------------------------------------------------Fonction récursive et itérative ---------------------------
#Q1 :
def factorielle_it(n):
fact = 1
for i in range(n,0,-1) :
fact = fact * i
return fact
#print(factorielle_it(6))
#Q2 :
def factorielle_rec(n):
if n < 2 : return 1
else :
return n*factorielle_rec(n-1)
#print(factorielle_rec(6))
#Q3
def combinaison_it(p,n):
if p == 0 or p == n: return 1
else:
return (factorielle_rec(n)/(factorielle_rec(p)*factorielle_rec(n-p)))
print(combinaison_it(6,49))
#Q4
def combinaison_rec(p,n):
if p == 0 or p == n : return 1
else :
return combinaison_rec(p,n-1) + combinaison_rec(p-1,n-1)
print(combinaison_rec(6,49))
1 / 2 100%

DS INFO 1TSI2 ADOCH

Telechargé par Youness Ztati
La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !