python-CSD-kursu/python-temel/get_mean_stddev.py

20 lines
361 B
Python
Raw Normal View History

2023-05-23 17:06:36 +03:00
import math
def get_mean_stddev(iterable):
total = 0
count = 0
for x in iterable:
total += x
count += 1
mean = total / count
total = 0
for x in iterable:
total += (x - mean) ** 2
stddev = math.sqrt(total / count)
return mean, stddev
mean, stddev = get_mean_stddev([1, 2, 5, 6, 8])
print(mean, stddev)