Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def average_and_variance(x):
- N = len(x)
- avg = sum(x) / N
- w = (1/(N - 1)) * (sum((xi - avg) ** 2 for xi in x))
- return avg, w
- list = []
- while True:
- x = int(input("Podaj liczby do tablicy: "))
- if x == 0:
- break
- list.append(x)
- avg, w = average_and_variance(list)
- print("Średnia wynosi:", avg)
- print("Wariancja wynosi:", w)
- avg, w = average_and_variance([3, 3, 3, 3])
- print("Średnia dla (3,3,3,3) wynosi:", avg)
- print("Wariancja dla (3,3,3,3) wynosi:", w)
- avg, w = average_and_variance([5, 6, 7, 8, 9])
- print("Średnia dla (5,6,7,8,9) wynosi:", avg)
- print("Wariancja dla (5,6,7,8,9) wynosi:", w)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement