Python Programing: An Introduction To Computer Science: Data Collections
Python Programing: An Introduction To Computer Science: Data Collections
An Introduction to
Computer Science
Chapter 11
Data Collections
def main():
sum = 0.0
count = 0
xStr = input("Enter a number (<Enter> to quit) >> ")
while xStr != "":
x = eval(xStr)
sum = sum + x
count = count + 1
xStr = input("Enter a number (<Enter> to quit) >> ")
print("\nThe average of the numbers is", sum / count)
main()
s i
n 1
Here x is the mean, xi represents the ith
data value and n is the number of data
values.
2
The expression x xi is the square of the
“deviation” of an individual item from the
mean.
Python Programming, 2/e 9
Sample Problem:
Simple Statistics
The numerator is the sum of these
squared “deviations” across all the data.
Suppose our data was 2, 4, 6, 9, and
13.
The mean is 6.8
The numerator of the standard deviation is
6.8 2 6.8 4 6.8 6 6.8 9 6.8 13
2 2 2 2 2
149.6
149.6
s 37.4 6.11
5 1
Python Programming, 2/e 10
Sample Problem:
Simple Statistics
As you can see, calculating the standard
deviation not only requires the mean
(which can’t be calculated until all the
data is entered), but also each
individual data element!
We need some way to remember these
values as they are entered.
<list>.pop(i) Deletes the ith element of the list and returns its value.
data = getNumbers()
xbar = mean(data)
std = stdDev(data, xbar)
med = median(data)
Into this:
self.pips[0].setFill(self.foreground)
self.pips[3].setFill(self.foreground)
self.pips[6].setFill(self.foreground)
on = onTable[value]
for i in on:
self.pips[i].setFill(self.foreground)
on = onTable[value]
for i in on:
self.pips[i].setFill(self.foreground)