#!/usr/bin/python3
################################################################################
# Python statistics/analytics functions
################################################################################
print("Content-Type: text/html \n")     #http header with newline char (required for the web)
print('<pre>')                          #to produce better display on the web 

import statistics
import random

list1 = [0,1,2,3,4,5,6,7,8,9]
print('Data Points:\t', list1)

print('Count:     \t', len(list1))
print('Sum:       \t', sum(list1))
print('Min:       \t', min(list1))
print('Max:       \t', max(list1))
print('Range:     \t', max(list1) - min(list1))

print('Average:   \t', statistics.mean(list1))

print('Median:    \t', statistics.median(list1))
print('Median-low:\t', statistics.median_low(list1))
print('Median-hi: \t', statistics.median_high(list1))

try:                                                        #you can do try/except this way
    mode = statistics.mode(list1)
except:
    mode = 'no/multi mode'
print('Mode: \t\t', mode)

try:                                                        #or this way
    print('Mode: \t\t', statistics.mode(list1))
except statistics.StatisticsError as e:
    print('Mode: \t\t', e)

print('Sample std dev:     \t', statistics.stdev(list1))
print('Population std dev: \t', statistics.pstdev(list1))
print()


rand = random.randint(1,10)
print('A random number 1-10: \t', rand)

sample1 = random.sample(list1,5)
print('Random sample from above list: \t', sample1)
 
list2  = list(list1)                                #copy list1 into list2

random.shuffle(list2)
print('Data shuffled from above list: \t', list2)