Advertisement
Rementai

Wariancja

Mar 16th, 2023
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. def average_and_variance(x):
  2.     N = len(x)
  3.     avg = sum(x) / N
  4.     w = (1/(N - 1)) * (sum((xi - avg) ** 2 for xi in x))
  5.     return avg, w
  6.  
  7. list = []
  8. while True:
  9.     x = int(input("Podaj liczby do tablicy: "))
  10.     if x == 0:
  11.         break
  12.     list.append(x)
  13.  
  14. avg, w = average_and_variance(list)
  15. print("Średnia wynosi:", avg)
  16. print("Wariancja wynosi:", w)
  17.  
  18. avg, w = average_and_variance([3, 3, 3, 3])
  19. print("Średnia dla (3,3,3,3) wynosi:", avg)
  20. print("Wariancja dla (3,3,3,3) wynosi:", w)
  21.  
  22. avg, w = average_and_variance([5, 6, 7, 8, 9])
  23. print("Średnia dla (5,6,7,8,9) wynosi:", avg)
  24. print("Wariancja dla (5,6,7,8,9) wynosi:", w)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement