repl.it
@TreyvanMcDonald/

Coding with Text Files - 4th Assignment

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
print()
print("Date: 2/25/2019")
print("Name: Treyvan McDonald")
print("Period 8: 8th Period Coding")
print("Coding with Text Files - 4th Assignment")
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:
  splitLineUp = line.split(',')
  
  name = splitLineUp[0]
  
  subject = splitLineUp[1]
  
  grade = splitLineUp[2]
  
  if name in studentNames:
    #print("The name is in it!")
    none = 56
  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()

ELAAverage1 = et1/3
ELAAverage2 = et2/3
ELAAverage3 = et3/4
ELAAverage4 = et4/4
ELAAverage5 = et5/4
mathAverage1 = mt1/3
mathAverage2 = mt2/4
mathAverage3 = mt3/3
mathAverage4 = mt4/3
mathAverage5 = mt5/4
scienceAverage1 = st1/4
scienceAverage2 = st2/3
scienceAverage3 = st3/3
scienceAverage4 = st4/3
scienceAverage5 = st5/2

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()