Skip to content

Commit ac78d7b

Browse files
committed
Add student result processor utility
1 parent 3c88735 commit ac78d7b

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

other/student_result_processor.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
Student Result Processor
3+
4+
This module provides utility functions to process student results,
5+
including separating passed and failed students, identifying top
6+
performers, and calculating pass percentage.
7+
"""
8+
9+
10+
def separate_students(students, pass_mark=75):
11+
"""
12+
Separate students into passed and failed lists.
13+
14+
:param students: List of dictionaries with keys 'name' and 'marks'
15+
:param pass_mark: Minimum marks required to pass
16+
:return: Tuple (passed_students, failed_students)
17+
"""
18+
passed = [s for s in students if s["marks"] >= pass_mark]
19+
failed = [s for s in students if s["marks"] < pass_mark]
20+
return passed, failed
21+
22+
23+
def top_performers(students, threshold=90):
24+
"""
25+
Get students scoring above a given threshold.
26+
27+
:param students: List of student dictionaries
28+
:param threshold: Minimum marks for top performers
29+
:return: List of top-performing students
30+
"""
31+
return [s for s in students if s["marks"] >= threshold]
32+
33+
34+
def pass_percentage(students, pass_mark=75):
35+
"""
36+
Calculate pass percentage.
37+
38+
:param students: List of student dictionaries
39+
:param pass_mark: Minimum marks required to pass
40+
:return: Pass percentage as float
41+
"""
42+
if not students:
43+
return 0.0
44+
45+
passed_count = sum(1 for s in students if s["marks"] >= pass_mark)
46+
return (passed_count / len(students)) * 100
47+
48+
49+
if __name__ == "__main__":
50+
sample_students = [
51+
{"name": "Pranav", "marks": 90},
52+
{"name": "Amit", "marks": 40},
53+
{"name": "Sneha", "marks": 95},
54+
{"name": "Rahul", "marks": 72},
55+
]
56+
57+
passed, failed = separate_students(sample_students)
58+
top = top_performers(sample_students)
59+
percentage = pass_percentage(sample_students)
60+
61+
print("Passed:", passed)
62+
print("Failed:", failed)
63+
print("Top Performers:", top)
64+
print("Pass Percentage:", percentage)
65+

0 commit comments

Comments
 (0)