Marks and average
Hints and examples are shown, check as often as you like, no timer.
Subject
We want to analyse the marks (out of 20) of a group of students: compute the average and count the marks above it.
Question 1
5 ptsWrite a function remplir(n) that reads n real marks between 0 and 20 (each invalid mark is read again) and returns them in a list.
remplir(3) ⟵ 12, 8.5, 15 → [12.0, 8.5, 15.0]
Hint
Use float(input()) — marks can be 8.5.
Question 2
5 ptsWrite a function moyenne(t) that returns the average of the list t.
round(moyenne([10, 12, 14]), 2) → 12.0
Hint
Sum the elements, then divide by len(t).
Question 3
4 ptsWrite a function nb_sup(t, m) that returns how many marks of t are strictly greater than m.
nb_sup([10, 12, 14], 12) → 1
Hint
Strictly greater: use >, not >=.
Question 4
6 ptsMain program: read n (1 ≤ n ≤ 30, repeat otherwise), fill the list, then display "Moyenne = X" (X rounded to 2 decimals) and "Au-dessus de la moyenne : Y".
Inputs: 3, 10, 12, 14 → Moyenne = 12.0 ⏎ Au-dessus de la moyenne : 1
Hint
print("Moyenne =", round(m, 2))
Your program
Saved automatically in this browser.
One line per input() call, used by “Run”.
Model solution
def remplir(n):
t = []
for i in range(n):
x = float(input("Note : "))
while not (0 <= x <= 20):
x = float(input("Note : "))
t.append(x)
return t
def moyenne(t):
s = 0
for x in t:
s = s + x
return s / len(t)
def nb_sup(t, m):
nb = 0
for x in t:
if x > m:
nb = nb + 1
return nb
# Programme principal
n = int(input("Nombre d'élèves : "))
while not (1 <= n <= 30):
n = int(input("Nombre d'élèves : "))
t = remplir(n)
m = moyenne(t)
print("Moyenne =", round(m, 2))
print("Au-dessus de la moyenne :", nb_sup(t, m))
The first run downloads Python (~6 MB) and can take a few seconds.