Skip to content

Instantly share code, notes, and snippets.

@mariack
Last active August 29, 2015 14:17
Show Gist options
  • Save mariack/9afa7b06f690b74d6296 to your computer and use it in GitHub Desktop.
Save mariack/9afa7b06f690b74d6296 to your computer and use it in GitHub Desktop.
import math
INPUTS = []
RESULTS = []
def main():
addToList()
a = len(INPUTS)
print("Count of List: ", a)
b = sum(INPUTS)
print("The sum of the list is: %d." % b)
c = avgList(INPUTS)
print("The average of the list is: %0.2f" % c)
minMax()
e = stdDev()
print("The standard deviation is: %0.3f" % e)
d = INPUTS.sort()
print("Sorted list: ", INPUTS)
RESULTS.insert(0, len(INPUTS))
RESULTS.insert(1, sum(INPUTS))
RESULTS.insert(2, avgList(INPUTS))
RESULTS.insert(3, max(INPUTS))
RESULTS.insert(4, min(INPUTS))
RESULTS.insert(5, e)
print("The results are: ", RESULTS )
def addToList():
stop = False
while(not stop):
number = input("Enter a number to be put into a list. Enter 's' to end list: ")
if number == 's':
print("End of list.")
stop = True
else:
INPUTS.append(int(number))
print(INPUTS)
def avgList(x):
avg = sum(x)/len(x)
return avg
def stdDev():
deviationList = []
avg = avgList(INPUTS)
for x in INPUTS:
s = (x - avg)**2
deviationList.append(s)
m = sum(deviationList)/len(INPUTS)
sigma = math.sqrt(m)
return sigma
def minMax():
maximum = INPUTS[0]
minimum = maximum
for x in INPUTS[0:]:
if (x > maximum):
maximum = x
elif (x < minimum):
minimum = x
print("The max number is: ", maximum)
print("The min number is: ", minimum)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment