Created
October 27, 2016 15:00
-
-
Save z3oc/1273dfcd9908c1e1da73b135bfb38c57 to your computer and use it in GitHub Desktop.
Calc GPA from txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
file = open(sys.argv[1]) | |
gradetotal = 0 | |
pointtotal = 0 | |
def calcGPA(grade,point,method): | |
global gradetotal | |
global pointtotal | |
if method == "HUST": | |
g = (grade-75)*0.1+3.0 | |
if g > 4.0: g = 4.0 | |
gradetotal += g*point | |
pointtotal += point | |
if method == "100": | |
gradetotal += grade*point | |
pointtotal += point | |
if method == "4.0": | |
g = grade//10 - 5 | |
if grade == 100: g -= 1 | |
gradetotal += g*point | |
pointtotal += point | |
for subject in file: | |
[grade, point] = subject.split() | |
calcGPA(float(grade),float(point),sys.argv[2]) | |
file.close() | |
gpa = gradetotal/pointtotal | |
print(gpa) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment