repl.it
Python

No description

fork
loading
Files
  • main.py
  • grades.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
print()
print("Date: 2/25/2019")
print("Name: Treyvan McDonald")
print("Period 8: 8th Period Coding")
print("Creating a bigger Text File and then reading it.")
print()

fh = open("grades.txt", "w")
fh.write("Treyvan McDonald, Math, 68\n")
fh.write("Treyvan McDonald, ELAR, 93\n")
fh.write("Treyvan McDonald, Math, 72\n")
fh.close()

fp = open("grades.txt", "r")
line = fp.readline()
cnt = 1
total_grade = 0
while line:
  print("Line", cnt, ": " + line)
  split_line_up = line.split(",")
  print(split_line_up)
  name = split_line_up[0]
  print("Student's name is: " + name)
  subject = split_line_up[1]
  print("Student's subject is: " + subject)
  grade = int(split_line_up[2])
  print("Student's grade is: ", grade)
  total_grade += grade
  print()
  line = fp.readline()
  cnt += 1

fp.close()

print("The student's average is: ", total_grade/(cnt-1))