quickGrade 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
quickGrade/__init__.py ADDED
File without changes
quickGrade/cli.py ADDED
@@ -0,0 +1,75 @@
1
+ import argparse
2
+
3
+ from quickGrade.grades import (
4
+ letter_to_gpa,
5
+ letter_to_percent,
6
+ gpa_to_letter,
7
+ gpa_to_percent,
8
+ percent_to_gpa,
9
+ percent_to_letter,
10
+ )
11
+
12
+
13
+ def main():
14
+ parser = argparse.ArgumentParser(
15
+ description="A tool to convert between letter grades, percentages, and GPAs"
16
+ )
17
+
18
+ input_group = parser.add_mutually_exclusive_group(required=True)
19
+
20
+ input_group.add_argument(
21
+ "--letter", type=str, help="The student grade as a letter grade"
22
+ )
23
+ input_group.add_argument(
24
+ "--percent", type=int, help="The student grade as a percentage"
25
+ )
26
+ input_group.add_argument(
27
+ "--gpa", type=float, help="The student grade as a Grade Point Average"
28
+ )
29
+
30
+ parser.add_argument(
31
+ "--output",
32
+ type=str.lower,
33
+ choices=["gpa", "percent", "letter"],
34
+ required=True,
35
+ help="Preferred output method: gpa, percent, or letter",
36
+ )
37
+
38
+ args = parser.parse_args()
39
+
40
+ if args.letter is not None:
41
+ inputVal = args.letter
42
+
43
+ if args.output == "gpa":
44
+ result = "GPA: " + str(letter_to_gpa(inputVal))
45
+ elif args.output == "percent":
46
+ result = "Percent: " + str(letter_to_percent(inputVal))
47
+ else:
48
+ result = "Letter: " + str(inputVal).upper().strip()
49
+
50
+ elif args.gpa is not None:
51
+ inputVal = args.gpa
52
+
53
+ if args.output == "gpa":
54
+ result = "GPA: " + str(inputVal)
55
+ elif args.output == "percent":
56
+ result = "Percent: " + str(gpa_to_percent(inputVal))
57
+ else:
58
+ result = "Letter: " + str(gpa_to_letter(inputVal))
59
+
60
+ else:
61
+ inputVal = args.percent
62
+
63
+ if args.output == "gpa":
64
+ result = "GPA: " + str(percent_to_gpa(inputVal))
65
+ elif args.output == "percent":
66
+ result = "Percent: " + str(inputVal)
67
+ else:
68
+ result = "Letter: " + str(percent_to_letter(inputVal))
69
+
70
+ print(result)
71
+ return 0
72
+
73
+
74
+ if __name__ == "__main__":
75
+ raise SystemExit(main())
quickGrade/grades.py ADDED
@@ -0,0 +1,111 @@
1
+ gradeRanges = {
2
+ (97, 100): ["A+", 4.0],
3
+ (93, 96): ["A", 3.9],
4
+ (90, 92): ["A-", 3.7],
5
+ (87, 89): ["B+", 3.3],
6
+ (83, 86): ["B", 3.0],
7
+ (80, 82): ["B-", 2.7],
8
+ (77, 79): ["C+", 2.3],
9
+ (73, 76): ["C", 2.0],
10
+ (70, 72): ["C-", 1.7],
11
+ (67, 69): ["D+", 1.3],
12
+ (63, 66): ["D", 1.0],
13
+ (60, 62): ["D-", 0.7],
14
+ (0, 59): ["F", 0.0],
15
+ }
16
+
17
+
18
+ def percent_to_letter(percent: int) -> str:
19
+ """Input a percent grade and output the corresponding letter grade
20
+
21
+ Args:
22
+ percent (int): The input percent
23
+
24
+ Returns:
25
+ str | ValueError: The output letter grade
26
+ """
27
+ if percent < 0 or percent > 100:
28
+ raise ValueError("Please enter a percent between 0-100 inclusive")
29
+ for key, val in gradeRanges.items():
30
+ min, max = key
31
+ if min <= percent <= max:
32
+ return val[0]
33
+ raise ValueError("Unknown error happened ")
34
+
35
+
36
+ def letter_to_percent(
37
+ letter: str, min: bool = False, max: bool = False, avg: bool = True
38
+ ) -> int:
39
+ total = 0
40
+ if min:
41
+ total += 1
42
+ if max:
43
+ total += 1
44
+ if avg:
45
+ total += 1
46
+ if total != 1:
47
+ raise ValueError("Please pick only one of max, min, or avg as an arg")
48
+
49
+ for key, val in gradeRanges.items():
50
+ if val[0] == letter:
51
+ minV, maxV = key
52
+ if min:
53
+ return min
54
+ if max:
55
+ return max
56
+ return int(sum(key) / 2)
57
+
58
+ raise ValueError("Unknown error happened")
59
+
60
+ def percent_to_gpa(percent:int) -> float:
61
+ if percent < 0 or percent > 100:
62
+ raise ValueError("Please enter a percent between 0-100 inclusive")
63
+ for key, val in gradeRanges.items():
64
+ min, max = key
65
+ if min <= percent <= max:
66
+ return val[1]
67
+ raise ValueError("Unknown error happened ")
68
+
69
+ def gpa_to_percent(gpa:float,min: bool = False, max: bool = False, avg: bool = True) -> int:
70
+ total = 0
71
+ if min:
72
+ total += 1
73
+ if max:
74
+ total += 1
75
+ if avg:
76
+ total += 1
77
+ if total != 1:
78
+ raise ValueError("Please pick only one of max, min, or avg as an arg")
79
+
80
+ for key, val in gradeRanges.items():
81
+ if val[1] == gpa:
82
+ minV, maxV = key
83
+ if min:
84
+ return min
85
+ if max:
86
+ return max
87
+ return int(sum(key) / 2)
88
+ raise ValueError("Unknown error happened")
89
+
90
+ def gpa_to_letter(gpa: float) -> str:
91
+ gpaV = gpa_to_percent(gpa)
92
+ return percent_to_letter(gpaV)
93
+
94
+ def letter_to_gpa(letter: str) -> float:
95
+ return percent_to_gpa(letter_to_percent(letter))
96
+
97
+ def weightedGPA(percent: int, course_type: str = "regular") -> float:
98
+ base_gpa = percent_to_gpa(percent)
99
+
100
+ course_type = course_type.lower().strip()
101
+
102
+ if course_type == "regular":
103
+ return base_gpa
104
+
105
+ if course_type == "honors":
106
+ return min(base_gpa + 0.5, 5.0)
107
+
108
+ if course_type in ["ap", "ib"]:
109
+ return min(base_gpa + 1.0, 5.0)
110
+
111
+ raise ValueError("course_type must be regular, honors, ap, or ib.")
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: quickGrade
3
+ Version: 0.1.0
4
+ Summary: A simple grade conversion tool
5
+ Author: Albin Zieme
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
@@ -0,0 +1,9 @@
1
+ quickGrade/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ quickGrade/cli.py,sha256=IAbdkSEF8yH3vWrxGrZ3BzTLdOPsDDNsiZYzUKvB9ds,2023
3
+ quickGrade/grades.py,sha256=4j9P_acqXU4FujSsPZ0zJXoHcYdzxbUe3HncX9VdLuI,3034
4
+ quickgrade-0.1.0.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ quickgrade-0.1.0.dist-info/METADATA,sha256=3O8jcrDmAO8gAySpqIBRZMfllZVdfoxMXkiQdoUstNQ,221
6
+ quickgrade-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
+ quickgrade-0.1.0.dist-info/entry_points.txt,sha256=a9NQCGpJZ9CQnhcViU4oXwtFl3sHyHVS5YZBnz5OA1Y,51
8
+ quickgrade-0.1.0.dist-info/top_level.txt,sha256=l35fs3eQuy1556Y45Kt96YPf9F_ZtzjuLLPzzEUdX6U,11
9
+ quickgrade-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ quickgrade = quickGrade.cli:main
File without changes
@@ -0,0 +1 @@
1
+ quickGrade