Media aritmetica
La media aritmetica di 2 (3) valori numerici
def media2(x, y):
return (x+y)/2
#######################
a=18
b=19
c=28
... media2(a, b) # 18.5
... media2(a, c) # 23.0
... media2(b, c) # 23.5
def media3(x, y, z):
return (x+y+z)/3
#######################
a=18
b=19
c=28
... media3(a, b, c) # 21.67
Media geometrica
import math
def media2g(x, y):
return math.sqrt(x*y)
#######################
a=18
b=19
c=28
... media2g(a, b) # 18.49
... media2g(a, c) # 22.45
... media2g(b, c) # 23.065
import math
def media3g(x, y, z):
return math.pow(x*y*z, 1/3)
#######################
a=18
b=19
c=28
... media3g(a, b, c) # 21.235
Continua…
- Media armonica?
- Media pesata?
- Se i dati sono più di 3 (2?) si passa alle liste…