Advertisement
Guest User

Standard Deviation

a guest
Oct 19th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. how_many = input("How many numbers?")
  2. how_many = int(how_many)
  3. numbers = []
  4. total = 0
  5. sdtotal = 0
  6.  
  7. for number_count in range(how_many):
  8. number = input("Enter number " + str(number_count + 1) + ">")
  9. numbers.append(number)
  10. #
  11. for number_count in range(how_many):
  12. number = int(numbers[number_count])
  13. total = total + number
  14. mean = total/how_many
  15. print("The mean value is " + str(mean) + ".")
  16.  
  17. for number_count in range(how_many):
  18. number = int(numbers[number_count])
  19. variance = number - mean
  20. number = variance * variance
  21. sdtotal = sdtotal + number
  22.  
  23. popsd = sdtotal / how_many
  24. samplesd = sdtotal / (how_many - 1)
  25.  
  26. import math
  27. popsd = math.sqrt(popsd)
  28. samplesd = math.sqrt(samplesd)
  29.  
  30. print ("The population standard deviation is " + str(popsd) + ".")
  31. print("The sample standard deviation is " + str(samplesd) + ".")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement