# TP 7 3.7.3 Course à pied # initialisation ############################################################ import random def init(n): distances = [] for _ in range(n): distances.append(round(random.uniform(0, 100), 2)) return distances l = init(365) print(l) # moyenne ################################################################### def averages(l): sums = [0, 0, 0, 0, 0, 0, 0] counts = [0, 0, 0, 0, 0, 0, 0] for i in range(len(l)): day = i%7 sums[day] += l[i] counts[day] += 1 averages = [] for i in range(7): d = sums[i] n = counts[i] if n > 0: averages.append(d/n) else: averages.append(0) return averages day_averages = averages(l) print(day_averages) # histogramme ############################################################### from turtle import * left(90) def rect(h, w): forward(h) right(90) forward(10) left(90) backward(h) w = 10 for h in day_averages: rect(h, w) left(90) forward(w*len(day_averages)) right(90) mainloop()