@SebastianCooke/

Working With Text Files 4

Python

No description

fork
loading
Files
  • main.py
  • averages.txt
  • bunchOfGrades.txt
main.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
print("4/5/2019")
print("Sebastian Cooke")
print("4th Period Coding")
print("Working With Text Files 4")
print()

et1 = 0
et2 = 0
et3 = 0
et4 = 0
et5 = 0
mt1 = 0
mt2 = 0
mt3 = 0
mt4 = 0
mt5 = 0
st1 = 0
st2 = 0
st3 = 0
st4 = 0
st5 = 0
ELAGrades1 = []
ELAGrades2 = []
ELAGrades3 = []
ELAGrades4 = []
ELAGrades5 = []
mathGrades1 = []
mathGrades2 = []
mathGrades3 = []
mathGrades4 = []
mathGrades5 = []
scienceGrades1 = []
scienceGrades2 = []
scienceGrades3 = []
scienceGrades4 = []
scienceGrades5 = []
studentNames = []



fp = open("bunchOfGrades.txt" , "r")
line = fp.readline()

while line:
  split = line.split(',')
  
  name = split[0]
  
  subject = split[1]
  
  grade = split[2]
  
  if name in studentNames:
    y = 99 
  else:
    studentNames.append(name)
  
  if name == studentNames[0]:
    sNum = 1
  elif name == studentNames[1]:
    sNum = 2
  elif name == studentNames[2]:
    sNum = 3
  elif name == studentNames[3]:
    sNum = 4
  elif name == studentNames[4]:
    sNum = 5

  if subject == "ELA":
    if sNum == 1:
      ELAGrades1.append(int(grade))
      et1 += int(grade)
    elif sNum == 2:
      ELAGrades2.append(int(grade))
      et2 += int(grade)
    elif sNum == 3:
      ELAGrades3.append(int(grade))
      et3 += int(grade)
    elif sNum == 4:
      ELAGrades4.append(int(grade))
      et4 += int(grade)
    elif sNum == 5:
      ELAGrades5.append(int(grade))
      et5 += int(grade)

  if subject == "Science":
    if sNum == 1:
      scienceGrades1.append(int(grade))
      st1 += int(grade)
    elif sNum == 2:
      scienceGrades2.append(int(grade))
      st2 += int(grade)
    elif sNum == 3:
      scienceGrades3.append(int(grade))
      st3 += int(grade)
    elif sNum == 4:
      scienceGrades4.append(int(grade))
      st4 += int(grade)
    elif sNum == 5:
      scienceGrades5.append(int(grade))
      st5 += int(grade)

  if subject == "Math":
    if sNum == 1:
      mathGrades1.append(int(grade))
      mt1 += int(grade)
    elif sNum == 2:
      mathGrades2.append(int(grade))
      mt2 += int(grade)
    elif sNum == 3:
      mathGrades3.append(int(grade))
      mt3 += int(grade)
    elif sNum == 4:
      mathGrades4.append(int(grade))
      mt4 += int(grade)
    elif sNum == 5:
      mathGrades5.append(int(grade))
      mt5 += int(grade)
  

  line = fp.readline()


fp.close()

ELAlen1 = len( ELAGrades1 )
ELAGrades1sum=sum(ELAGrades1)
#print ("ELAGrades1 is", ELAlen1,)

ELAlen2 = len(ELAGrades2)#different person
ELAGrades2sum=sum(ELAGrades2)
#print ("ELAGrades2 is", ELAlen2,)

ELAGrades3sum=sum(ELAGrades3)
ELAlen3 = len(ELAGrades3)
#print ("ELAGrades3 is" , ELAlen3, )

ELAGrades4sum=sum(ELAGrades4)
ELAlen4 = len(ELAGrades4)
#print("ELAGrades4 is" ,ELAlen4,)

ELAGrades5sum=sum(ELAGrades5)
ELAlen5 = len(ELAGrades5)
##print("ELAGrades5 is", ELAlen5,)

ELAAverage1 = ELAGrades1sum/ELAlen1
ELAAverage2 = ELAGrades2sum/ELAlen2
ELAAverage3 = ELAGrades3sum/ELAlen3
ELAAverage4 = ELAGrades4sum/ELAlen4
ELAAverage5 = ELAGrades5sum/ELAlen5

mathlen1= len( mathGrades1 )
mathGrades1sum=sum(mathGrades1)
#print ("mathGrades1 is", mathlen1,)

mathlen2= len( mathGrades2 )
mathGrades2sum=sum(mathGrades2)
#print ("mathGrades2 is", mathlen2,)

mathlen3= len( mathGrades3 )
mathGrades3sum=sum(mathGrades3)
#print ("mathGrades3 is", mathlen3,)

mathlen4= len( mathGrades4 )
mathGrades4sum=sum(mathGrades4)
#print ("mathGrades4 is", mathlen4,)

mathlen5= len( mathGrades5 )
mathGrades5sum=sum(mathGrades5)
#print ("mathGrades5 is", mathlen5,)

mathAverage1 = mathGrades1sum/mathlen1
mathAverage2 = mathGrades2sum/mathlen2
mathAverage3 = mathGrades3sum/mathlen3
mathAverage4 = mathGrades4sum/mathlen4
mathAverage5 = mathGrades5sum/mathlen5

sciencelen1= len( scienceGrades1 )
scienceGrades1sum=sum(scienceGrades1)
#print ("scienceGrades1 is", sciencelen1,)

sciencelen2= len( scienceGrades2 )
scienceGrades2sum=sum(scienceGrades2)
#print ("scienceGrades2 is", sciencelen2,)

sciencelen3= len( scienceGrades3 )
scienceGrades3sum=sum(scienceGrades3)
#print ("scienceGrades3 is", sciencelen3,)

sciencelen4= len( scienceGrades4 )
scienceGrades4sum=sum(scienceGrades4)
#print ("scienceGrades4 is", sciencelen4,)

sciencelen5= len( scienceGrades5 )
scienceGrades5sum=sum(scienceGrades5)
#print ("scienceGrades5 is", sciencelen5,)

scienceAverage1 =scienceGrades1sum/sciencelen1
scienceAverage2 =scienceGrades2sum/sciencelen2
scienceAverage3 =scienceGrades3sum/sciencelen3
scienceAverage4 =scienceGrades4sum/sciencelen4
scienceAverage5 =scienceGrades5sum/sciencelen5


fh = open("averages.txt", "w")
fh.write(studentNames[0]+","+"ELA,"+str(ELAAverage1)+"\n")
fh.write(studentNames[0]+","+"Math,"+str(mathAverage1)+"\n")
fh.write(studentNames[0]+","+"Science,"+str(scienceAverage1)+"\n")
fh.write(studentNames[1]+","+"ELA,"+str(ELAAverage2)+"\n")
fh.write(studentNames[1]+","+"Math,"+str(mathAverage2)+"\n")
fh.write(studentNames[1]+","+"Science,"+str(scienceAverage2)+"\n")
fh.write(studentNames[2]+","+"ELA,"+str(ELAAverage3)+"\n")
fh.write(studentNames[2]+","+"Math,"+str(mathAverage3)+"\n")
fh.write(studentNames[2]+","+"Science,"+str(scienceAverage1)+"\n")
fh.write(studentNames[3]+","+"ELA,"+str(ELAAverage4)+"\n")
fh.write(studentNames[3]+","+"Math,"+str(mathAverage4)+"\n")
fh.write(studentNames[3]+","+"Science,"+str(scienceAverage4)+"\n")
fh.write(studentNames[4]+","+"ELA,"+str(ELAAverage5)+"\n")
fh.write(studentNames[4]+","+"Math,"+","+str(mathAverage5)+"\n")
fh.write(studentNames[4]+","+"Science,"+str(scienceAverage5)+"\n")
fh.close()