quickgrade 0.1.1__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,157 @@
1
+ Metadata-Version: 2.4
2
+ Name: quickgrade
3
+ Version: 0.1.1
4
+ Summary: A simple CLI and Python package for converting between letter grades, percentages, and GPA.
5
+ Author: Albin Zieme
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # quickgrade
12
+
13
+ `quickgrade` is a simple Python package and command-line tool for converting between letter grades, percentages, and GPA values.
14
+
15
+ It can be used directly in the terminal or imported into your own Python projects.
16
+
17
+ ## Features
18
+
19
+ - Convert percentage grades to letter grades
20
+ - Convert percentage grades to GPA values
21
+ - Convert letter grades to percentages
22
+ - Convert letter grades to GPA values
23
+ - Convert GPA values to percentages
24
+ - Convert GPA values to letter grades
25
+ - Includes an easy-to-use command-line interface
26
+
27
+ ## Installation
28
+
29
+ Install with pip:
30
+
31
+ ```bash
32
+ pip install quickgrade
33
+ ```
34
+
35
+ ## CLI Usage
36
+
37
+ After installing, you can use the `quickgrade` command in your terminal.
38
+
39
+ ### Convert a letter grade to a GPA
40
+
41
+ ```bash
42
+ quickgrade --letter A --output gpa
43
+ ```
44
+
45
+ Output:
46
+
47
+ ```text
48
+ GPA: 3.9
49
+ ```
50
+
51
+ ### Convert a percentage to a letter grade
52
+
53
+ ```bash
54
+ quickgrade --percent 95 --output letter
55
+ ```
56
+
57
+ Output:
58
+
59
+ ```text
60
+ Letter: A
61
+ ```
62
+
63
+ ### Convert a GPA to a percentage
64
+
65
+ ```bash
66
+ quickgrade --gpa 3.7 --output percent
67
+ ```
68
+
69
+ Output:
70
+
71
+ ```text
72
+ Percent: 91
73
+ ```
74
+
75
+ ## CLI Arguments
76
+
77
+ | Argument | Description | Example |
78
+ |---|---|---|
79
+ | `--letter` | Input a letter grade | `--letter A-` |
80
+ | `--percent` | Input a percentage grade | `--percent 95` |
81
+ | `--gpa` | Input a GPA value | `--gpa 3.7` |
82
+ | `--output` | Choose the output type: `letter`, `percent`, or `gpa` | `--output letter` |
83
+
84
+ Only one input type should be used at a time.
85
+
86
+ ## Python Usage
87
+
88
+ You can also import the conversion functions in Python.
89
+
90
+ ```python
91
+ from quickGrade.grades import percent_to_letter, percent_to_gpa
92
+
93
+ print(percent_to_letter(95))
94
+ print(percent_to_gpa(95))
95
+ ```
96
+
97
+ Output:
98
+
99
+ ```text
100
+ A
101
+ 3.9
102
+ ```
103
+
104
+ ## Available Functions
105
+
106
+ ```python
107
+ percent_to_letter(percent)
108
+ percent_to_gpa(percent)
109
+
110
+ letter_to_percent(letter)
111
+ letter_to_gpa(letter)
112
+
113
+ gpa_to_percent(gpa)
114
+ gpa_to_letter(gpa)
115
+ ```
116
+
117
+ ## Example
118
+
119
+ ```python
120
+ from quickGrade.grades import letter_to_percent, letter_to_gpa
121
+
122
+ letter = "B+"
123
+
124
+ print(letter_to_percent(letter))
125
+ print(letter_to_gpa(letter))
126
+ ```
127
+
128
+ Output:
129
+
130
+ ```text
131
+ 88
132
+ 3.3
133
+ ```
134
+
135
+ ## Grade Scale
136
+
137
+ The default grading scale is:
138
+
139
+ | Percent Range | Letter Grade | GPA |
140
+ |---|---:|---:|
141
+ | 97-100 | A+ | 4.0 |
142
+ | 93-96 | A | 3.9 |
143
+ | 90-92 | A- | 3.7 |
144
+ | 87-89 | B+ | 3.3 |
145
+ | 83-86 | B | 3.0 |
146
+ | 80-82 | B- | 2.7 |
147
+ | 77-79 | C+ | 2.3 |
148
+ | 73-76 | C | 2.0 |
149
+ | 70-72 | C- | 1.7 |
150
+ | 67-69 | D+ | 1.3 |
151
+ | 63-66 | D | 1.0 |
152
+ | 60-62 | D- | 0.7 |
153
+ | 0-59 | F | 0.0 |
154
+
155
+ ## License
156
+
157
+ This project is licensed under the MIT License.
@@ -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.1.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ quickgrade-0.1.1.dist-info/METADATA,sha256=oRxkPwyBEwxnlvBzikITl2jHeLIjmnxTe_s8CQ4QLwI,2749
6
+ quickgrade-0.1.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
+ quickgrade-0.1.1.dist-info/entry_points.txt,sha256=a9NQCGpJZ9CQnhcViU4oXwtFl3sHyHVS5YZBnz5OA1Y,51
8
+ quickgrade-0.1.1.dist-info/top_level.txt,sha256=l35fs3eQuy1556Y45Kt96YPf9F_ZtzjuLLPzzEUdX6U,11
9
+ quickgrade-0.1.1.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