TheLegace

gpa.py

May 14th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. #
  2.  
  3. # gpa.py
  4. # author Vaibhav Kapoor
  5. # CopyLeft 2012
  6.  
  7. def main():
  8.     f = open('gpa.txt', 'r')
  9.     grades = ['F', 'E', 'D', 'D+', 'C', 'C+', 'B', 'B+', 'A', 'A+']
  10.     creditTotal = 0
  11.     points = 0
  12.     for line in f:
  13.         split = line.split()
  14.         if(split[-1] in grades):
  15.             credit = float(split[4])
  16.             grade = float(grades.index(split[-1]))
  17.             points += grade*credit
  18.             creditTotal += credit                  
  19.     print points / creditTotal
  20.     f.close()
  21.  
  22. main()
Advertisement
Add Comment
Please, Sign In to add comment