Skip to content

Instantly share code, notes, and snippets.

@Pk13055
Created June 17, 2017 13:23
Show Gist options
  • Save Pk13055/e827acf99562d78427b2f88809a7d9e0 to your computer and use it in GitHub Desktop.
Save Pk13055/e827acf99562d78427b2f88809a7d9e0 to your computer and use it in GitHub Desktop.
Small script to calculate cgpa
#!/usr/bin/python3
# enter details as follows credit mark credit mark ..
# ex: ./grades.py 5 A- 3 A 4 B- ...
from sys import argv as rd
grades = { 'A' : 10, 'A-' : 9, 'B' : 8, 'B-' : 7, 'C' : 6, 'C-' : 5 , 'D' : 4, 'F' : 2}
courses = list(map(lambda x: [float(x[0]), grades[x[-1]]], [[x, y] for x, y in zip(rd[1:], rd[1:][1:])][::2]))
print(sum([x[0] * x[-1] for x in courses]) / sum([x[0] for x in courses]))
@Pk13055
Copy link
Author

Pk13055 commented Jun 17, 2017

This script outputs your CGPA to stdout:

  • chmod 755 grades.py
  • ./grades.py <credit> <grade> <credit> <grade> ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment