Modules nécessaires :
from time import time
import matplotlib.pyplot as plt
from random import randint
def ecartMax(t):
L_max_global = []
for i in range(len(t)):
L_max_local = []
for j in range(i, len(t)):
L_max_local.append(abs([t[i]-t[j]]))
L_max_global.append(max(L_max_local))
return max(L_max_local)
data = [randint(0, 20) for k in range(48)]
Renvoie :
[0, 4, 9, 12, 16, 1, 1, 4, 3, 20, 7, 11, 2, 0, 11, 4, 12, 6,
3, 4, 11, 8, 0, 14, 9, 9, 1, 8, 17, 18, 6, 19, 8, 8, 16, 0,
3, 18, 5, 12, 18, 3, 16, 10, 18, 16, 17, 16]
TODO : faire la moyenne
plt.style.use('dark_background')
plt.figure()
plt.hist(data, range=(0, 20), bins=20, color='red', edgecolor='black')
plt.title('notes du DS 1')
plt.xlabel('notes')
plt.ylabel('effectifs')
plt.show()
Renvoie :
def ajout(p):
t0 = time()
fich = open('listepremiers', 'r')
L = fich.read()
fich.close()
L1 = L.split('\n')
L2 = L1[0:-1]
l = len(L2)
P = [int(L2[i]) for i in range(l)]
fich = open('listepremiers', 'a')
n = P[-1]
while len(P) < 1 + p:
n += 2
prem = True
k = 0
while P[k]**2 <= n and prem:
if n % P[k] == 0:
prem = False
k += 1
if prem:
P.append(n)
ch = str(n)+'\n'
fich.write(ch)
fich.close()
return time()-t0
print(ajout(999))
Voir le PDF