Advertisement
Guest User

Untitled

a guest
Mar 18th, 2013
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. # VARIABLE DEFINITIONs
  2.  
  3. currentName = ""
  4. course = ""
  5. grade = ""
  6. categoryTotal = 0
  7. eof = False
  8. grandTotal=0
  9. gradeFile = ""
  10.  
  11. #-----------------------------------------------------------------------
  12. # CONSTANT DEFINITIONS
  13.  
  14. #-----------------------------------------------------------------------
  15. # FUNCTION DEFINITIONS
  16. def startUp():
  17. global gradeFile,currentName,previousName,course,grade,eof
  18. print ("grade report\n").center(60).upper()
  19. print "name".upper(),"course".rjust(22).upper(),"grade".rjust(32).upper()
  20. print "-" * 60
  21. gradeFile = open("grades.txt","r")
  22. readRecord()
  23. previousName=""
  24. previousName= currentName
  25.  
  26.  
  27. def readRecord():
  28. global currentName, course,grade,eof,studentRecord,gradeFile
  29. studentRecord = gradeFile.readline()
  30. if studentRecord == "":
  31. eof = True
  32. else:
  33. currentName = studentRecord[0:20].strip()
  34. course = studentRecord[20:50].strip()
  35. grade = studentRecord[50:51].strip()
  36. eof = False
  37.  
  38. def gradesLoop():
  39. global eof,previousName,currentName,categoryTotal,course,grade
  40. while not eof:
  41. if currentName != previousName:
  42. categoryChange()
  43. if categoryTotal <= 1:
  44. tempStr = currentName.ljust(20)
  45. tempStr+= course.ljust(50)
  46. tempStr+= grade.ljust(51)
  47. else:
  48. tempStr+= course.ljust(50)
  49. tempStr+= grade.ljust(51)
  50.  
  51.  
  52. categoryTotal+=1
  53. readRecord()
  54.  
  55. def categoryChange():
  56. global categoryTotal,grandTotal,previousName,currentName
  57. print "Category count=", categoryTotal
  58. grandTotal+= categoryTotal
  59. categoryTotal=0
  60. previousName = currentName
  61.  
  62. def closeDown():
  63. global grandTotal, gradeFile
  64. categoryChange()
  65. print "Total courses taken by all students =", grandTotal
  66. gradeFile.close()
  67. #------------------------------------------------------------------------
  68. startUp()
  69. gradesLoop()
  70. closeDown()
  71.  
  72. raw_input("\nRun complete. Press the Enter key to exit.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement