Esempio n. 1
0
import sys
from random import randint
from modules.econ_statistics import Econ_Statistics

# Simple application to calculate sample data of a population
# Intended to show difference between population and sample and to
# show how the average of the [sample variance] approaches 0 as
# repetitions increase

data_list = [25, 24, 21, 23, 21, 20, 20, 20, 20, 20, 20, 20, 20, 20, 19, 21, 20, 20, 21, 21, 20, 20, 19, 18, 19, 19, 22, 25, 21, 20, 28, 22, 20, 20, 20, 21, 24]

ec = Econ_Statistics()

print("Population average: {}".format(ec.get_average(data_list)))
print("Population variance: {}".format(ec.get_variance(data_list)))

looped = 0
while 1:
    slist = []
    slist_avg = []
    slist_var = []
    try:
        ip = "y" if looped == 1 else raw_input("Would you like to sample the current list?\n> y - Yes\n> c - clear data\n> d - Display list\n>  ")
        if ip.lower() == "y":
            while 1:
                if len(data_list) == 0:
                    while 1:
                        try:
                            inp = raw_input("Add a number to the list:\n> d - Done\n> ")
                            if inp == "d":
                                break
#! /usr/bin/python3

#Application to calculate simple statistical data

import sys
import math
from modules.econ_statistics import Econ_Statistics
ec = Econ_Statistics()

data_list = [12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14,
            14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
            15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
            16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
            16, 16, 16]

data_mean = 0
data_median = 0
data_mode = 0

number = 0
print("Your current number list: " + str(data_list))
while 1:
    number = raw_input("Add a number or pick an option.\n> c - Clear data_list\n> d - Continue\n> ") if sys.version < (3,0) else input("Add a number or pick an option.\n> Enter 'clear' to clear data_list\n> Enter 'd' to continue\n> ")
    if number.lower() == "d" or number.lower() == "done":
        break
    elif number.lower == "c":
        data_list = []
        print("Cleared data_list")
    else:
        try:
            data_list.append(int(number))