Last active
March 3, 2018 10:39
-
-
Save Yuiki/d2394e18a424f17f26b3124a3f4ff8ba to your computer and use it in GitHub Desktop.
筑波大のGPA計算
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 csv | |
import sys | |
argv = sys.argv | |
if (len(argv) != 2): | |
print("Usage: python3 {} gpa.csv".format(argv[0])) | |
quit() | |
total_amount = 0 | |
total_gp = 0 | |
gp_map = {'A+': 4.3, 'A': 4, 'B': 3, 'C': 2} | |
filename = argv[1] | |
with open(filename, 'r') as f: | |
reader = csv.reader(f) | |
header = next(reader) | |
for row in reader: | |
classification = row[8] | |
evaluation = row[6] | |
if classification == 'C0' or evaluation in ['P', 'F']: continue | |
gp = gp_map.get(evaluation, 0) | |
amount = float(row[5]) | |
total_amount += amount | |
total_gp += gp * amount | |
print("Your GPA is {}.".format(total_gp / total_amount)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment