Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop a Python 3.4 program which will calculate and display information about

ID: 663184 • Letter: D

Question

Develop a Python 3.4 program which will calculate and display information about exam scores for the students in a class, as described below.

The program will prompt the user to enter the name of an input file. If that file cannot be opened, the program will prompt the user to re-enter the name of the input file.

Each line of the input file will represent one student and will have the following format:

Name (string, maximum of 20 characters)

Exam #1 score (integer, range 0 to 100)

Exam #2 score (integer, range 0 to 100)

The student

Explanation / Answer


class Student:
def __init__(self,s,p1,p2,avg):
   self.name = s
   self.paper_1 = p1
   self.paper_2 = p2
   self.average = avg

def avg1(std):
   total = 0.0
   for student in std:
       total += student.paper_1
   return total/float(len(std))

def avg2(std):
   total = 0.0
   for student in std:
       total += student.paper_2
   return total/float(len(std))


def table(std):
   for i in range(len(std)):
       for j in range(i+1,len(std)):
           if (std[i].name > std[j].name):
               Student temp = std[i]
               std[i] = std[j]
               std[j] = temp
   print 'Student Name Paper1 Marks Paper2 Marks average'
   for i in range(len(std)):
       print std[i].name+" "+str(std[i].paper_1)+" "+str(std[i].paper_2)+" "+str(std[i].average)

def main():
   print 'Enter filename to be open ',
   name = raw_input()
   f = open('urpop0090.txt','r')
   std = []
   for line in f:
       line = line.split()
       line[0] = line[0][:-1]
       avg = float(line[2])+float(line[3])/float(2)
       Student st(line[1] + " "+line[0],float(line[2]),float(line[3]),avg)
       std[i] = st
   table()
   avg1()
   avg2()
  
main()