title: Reading from raw_data.txt and writing to a results.txt file with processing in Python
body: <p>This is my first post. I have a function that asks for the number of students. Then, for each student, first three lines contain the following information: Student ID, name, and number of courses taken that semester. Now, for each course, the course number, credit hour, and the percentage of scores earned by the student is listed.</p>
  
  <pre><code>def rawdata():
      semester = 1
      if semester == 1:
          raw_file = open('raw_data.txt', 'a')
          total = 0.0
          total2 = 0.0
          num_students = int(input('Enter number of students: '))        
          for student in range(num_students):
              raw_file.write('Start' + '\n')
              student_id = input('Enter student ID: ')
              name = input('Enter Name: ')
              num_classes = int(input('Enter number of courses taken: '))
              raw_file.write(student_id + '\n')
              raw_file.write(name + '\n')
              raw_file.write(str(num_classes) + '\n')
              for classes in range(num_classes):
                  course_number = input('Enter Course Number: ')
                  credits = int(input('Enter Credit Hours: '))
                  GPA1 = float(input('Enter percentage grade for class: '))
                  raw_file.write(course_number + '\n')
                  raw_file.write(str(credits) + '\n')
                  raw_file.write(str(GPA1) + '\n')
                  total += credits
              raw_file.write('End' + '\n')
          raw_file.close()
          print('Data has been written')
  </code></pre>
  
  <p>All the data is listed to a txt file and now I need to PULL this information from my raw_data.txt which looks like(varies with inputs): </p>
  
  <pre><code>Start
  eh2727
  Josh D
  2
  MAT3000
  4
  95.0
  COM3000
  4
  90.0
  End
  Start
  ah2718
  Mary J
  1
  ENG3010
  4
  100.0
  End
  </code></pre>
  
  <p>and process it so that I can calculate each students GPA. I have each students block of info contained by a Start/End and I don't know how to read this info in my processing function in order for me to calculate their GPA. This is what I have so far:</p>
  
  <pre><code>def process():
      data = open('raw_data.txt', 'r')
      results = open('process_results.txt', 'w')
      buffer = []
      for line in data:
          if line.startswith('Start'):
              buffer = []
          buffer.append(line)
          if line.startswith("End"):
              for outline in buffer:
                  results.write(outline)
  </code></pre>
  
  <p>This simply writes it all into my results text and I don't know how to individually process each block of information to calculate the GPA. Any help would be greatly appreciated.</p>