#Name: Laraib Shaikh

#Student Number: 1205628

#Lab Section: L09

#Date: October 26,2012

#Lab_07

#This program computes the average grades



from graphics import*



def main():



    #ask the user to input the file name

    fname=raw_input ("Enter the file name with grades:")



    #process the file

    units, average = processFile(fname)

    print units,average





    #prints results in the graphics window

    #outputGUI (units, average)

    

def processFile(fname):

    fname = open(fname,"r")

    units = 0

    marks = 0



    for line in fname:

        data = line.split("\t")

        units += (float(data[1]))

        marks += (float ((data[1]))*float((data[2])))

        average = marks/units



    fname.close()

    return units,average

    



window = GraphWin ("Average results",500,200)

outputGUI(units,average)



#to print the results in the graphics window

def outputGUI (units, average):



    

    win.setCoords (0,0,100,100)



    #titles

    titleString = "Average results"

    titleLabel = Text(Point(50,90),titleString)

    titleLabel.setSize(35)

    titleLabel.setTextColor("blue")

    titleLabel.draw(win)



    #total number of units

    unitsString = "Total Number of Units=%i" %(units)

    unitsLabel = Text(Point(50,60),unitsString)

    unitsLabel.setSize(40)

    unitsLabel.setTextColor("grey")

    unitsLabel.draw(win)



    #to compute cumulative grade average

    averageString = "Cumulative Grade Average=%0.2f" %(average)

    averageLabel = Text(Point(40,30),averageString)

    averageLabel.setTextColor("green")

    averageLabel.draw(win)

    win.getMouse()

    win.close()



main()



"""

yes, the changes can be made without modifying any other part of the function because other parts of the program works on the basis of the given output from the processFile function









"""

