-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW7COmplete.py
193 lines (184 loc) · 5.56 KB
/
HW7COmplete.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#C:\Users\Richard\Desktop\case1.txt
import math
#====================================================
# Name: Header
# Parameters: NONE
# Returns: NONE
# Input from Keyboard: NONE
# Output to Screen: Prints header at top of document
#Description: Header code.
#Known Errors: NONE
def printHeader():
print "Homework Assignment 4"
print "September 27, 2010"
print "CSE 1310-003"
print "Richard Berry"
print "ID# 1000739465"
return
#====================================================
#====================================================
# Name: OpenFile
# Parameters: NONE
# Returns: NONE
# Input from Keyboard: The full path of the document.
# Output to Screen: The list of items in the document.
#Description: Makes CSV document into list, and makes it a global variable.
#Known Errors: NONE
def myOpenFile():
filename=raw_input("Input Filename (Note: Input full filepath):")
file=open(filename,'r')
myString=file.read()
myStringList= myString.split(',')
myIntegerList=[]
file.close()
for item in myStringList:
num=int(item)
myIntegerList.append(num)
local_variable=myIntegerList
global local_variable
return
#====================================================
#====================================================
# Name: MeanFunction
# Parameters: local_variable
# Returns: NONE
# Input from Keyboard: NONE
# Output to Screen: The mean of all numbers in file.
#Description:
#Known Errors: NONE
def meanFunction(local_variable):
total=sum(local_variable)
count=len(local_variable)
mean=total*1.0/float(count)
global mean
return
#====================================================
#====================================================
# Name:
# Parameters:
# Returns:
# Input from Keyboard:
# Output to Screen:
#Description:
#Known Errors:
def stdevFunction(local_variable):
total=0
for number in local_variable:
difference=mean - number
square=difference**2
total=total+square
n=len(local_variable)-1
variation=total/(n)
stdval=math.sqrt(variation)
global stdval
return
#====================================================
#====================================================
# Name:
# Parameters:
# Returns:
# Input from Keyboard:
# Output to Screen:
#Description:
#Known Errors: <function chartdiv at 0x0000000002583518>
def chartdiv (local_variable):
counter0=0
counter1=0
counter2=0
counter3=0
counter4=0
counter5=0
counter6=0
counter7=0
counter8=0
counter9=0
for number in (local_variable):
if number < mean-2.0*stdval: #final?
counter0 = counter0 + 1
continue
elif mean-2.0*stdval< number <=mean-1.5*stdval:
counter1 = counter1 + 1
continue
elif mean-1.5*stdval< number <=mean-1.0*stdval:
counter2 = counter2 + 1
continue
elif mean-1.0*stdval< number <=mean-0.5*stdval:
counter3 = counter3 + 1
continue
elif mean-0.5*stdval< number <=mean-0.0*stdval:
counter4 = counter4 + 1
continue
elif mean-0.0*stdval< number <=mean+0.5*stdval:
counter5 = counter5 + 1
continue
elif mean+0.5*stdval< number <=mean+1.0*stdval:
counter6 = counter6 + 1
continue
elif mean+1.0*stdval< number <=mean+1.5*stdval:
counter7 = counter7 + 1
continue
elif mean+1.5*stdval< number <=mean+2.0*stdval:
counter9 = counter8 + 1
continue
elif mean+2.0*stdval< number:
counter9 = counter9 + 1
continue
else:
print "Done"
print '%s %s' %("Counter #", "Count")
print '%s %s' %("Counter 0", counter0)
print '%s %s' %("Counter 1", counter1)
print '%s %s' %("Counter 2", counter2)
print '%s %s' %("Counter 3", counter3)
print '%s %s' %("Counter 4", counter4)
print '%s %s' %("Counter 5", counter5)
print '%s %s' %("Counter 6", counter6)
print '%s %s' %("Counter 7", counter7)
print '%s %s' %("Counter 8", counter8)
print '%s %s' %("Counter 9", counter9)
return "Done"
#====================================================
#====================================================
# Name:
# Parameters:
# Returns:
# Input from Keyboard:
# Output to Screen:
#Description:
def menu():
loop=True
while (loop):
print "-"*50
print "1. Open File"
print "2. Mean"
print "3. Standard Deviation"
print "4. Chart"
print "Q. Quit"
print "-"*50
print " "
option=raw_input("Please enter your selection:")
if (option=='1'):
myOpenFile()
print local_variable
elif (option=='2'):
myOpenFile()
meanFunction(local_variable)
print mean
elif (option=='3'):
myOpenFile()
meanFunction(local_variable)
stdevFunction(local_variable)
print stdval
elif (option=='4'):
myOpenFile()
meanFunction(local_variable)
stdevFunction(local_variable)
chartdiv(local_variable)
print chartdiv
elif (option=='q' or option=='Q'):
loop=False
else:
print "Invalid Option"
return
printHeader()
menu()