Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # VARIABLE DEFINITIONs
- currentName = ""
- course = ""
- grade = ""
- categoryTotal = 0
- eof = False
- grandTotal=0
- gradeFile = ""
- #-----------------------------------------------------------------------
- # CONSTANT DEFINITIONS
- #-----------------------------------------------------------------------
- # FUNCTION DEFINITIONS
- def startUp():
- global gradeFile,currentName,previousName,course,grade,eof
- print ("grade report\n").center(60).upper()
- print "name".upper(),"course".rjust(22).upper(),"grade".rjust(32).upper()
- print "-" * 60
- gradeFile = open("grades.txt","r")
- readRecord()
- previousName=""
- previousName= currentName
- def readRecord():
- global currentName, course,grade,eof,studentRecord,gradeFile
- studentRecord = gradeFile.readline()
- if studentRecord == "":
- eof = True
- else:
- currentName = studentRecord[0:20].strip()
- course = studentRecord[20:50].strip()
- grade = studentRecord[50:51].strip()
- eof = False
- def gradesLoop():
- global eof,previousName,currentName,categoryTotal,course,grade
- while not eof:
- if currentName != previousName:
- categoryChange()
- if categoryTotal <= 1:
- tempStr = currentName.ljust(20)
- tempStr+= course.ljust(50)
- tempStr+= grade.ljust(51)
- else:
- tempStr+= course.ljust(50)
- tempStr+= grade.ljust(51)
- categoryTotal+=1
- readRecord()
- def categoryChange():
- global categoryTotal,grandTotal,previousName,currentName
- print "Category count=", categoryTotal
- grandTotal+= categoryTotal
- categoryTotal=0
- previousName = currentName
- def closeDown():
- global grandTotal, gradeFile
- categoryChange()
- print "Total courses taken by all students =", grandTotal
- gradeFile.close()
- #------------------------------------------------------------------------
- startUp()
- gradesLoop()
- closeDown()
- raw_input("\nRun complete. Press the Enter key to exit.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement