from fractions import Fraction

n = int(input())
xs, fs = [], []
for _ in range(n):
    a, b = input().split(' ')
    x, f = int(a), Fraction(b)
    xs.append(x)
    fs.append(f)

mean = lambda xs, fs: sum(x * f for x, f in zip(xs, fs))
variance = lambda xs, fs: sum(x**2 * f for x, f in zip(xs, fs)) - mean(xs, fs)**2

mu, V = mean(xs, fs), variance(xs, fs)
sigma = V**0.5
print(f"Espérance : {mu}")
print(f"Variance : {V}")
print(f"Ecart-type : {sigma}")

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: