Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions other/student_result_processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
Student Result Processor

This module provides utility functions to process student results,
including separating passed and failed students, identifying top
performers, and calculating pass percentage.
"""


def separate_students(students, pass_mark=75):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file other/student_result_processor.py, please provide doctest for the function separate_students

Please provide return type hint for the function: separate_students. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: students

Please provide type hint for the parameter: pass_mark

"""
Separate students into passed and failed lists.

:param students: List of dictionaries with keys 'name' and 'marks'
:param pass_mark: Minimum marks required to pass
:return: Tuple (passed_students, failed_students)
"""
passed = [s for s in students if s["marks"] >= pass_mark]
failed = [s for s in students if s["marks"] < pass_mark]
return passed, failed


def top_performers(students, threshold=90):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file other/student_result_processor.py, please provide doctest for the function top_performers

Please provide return type hint for the function: top_performers. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: students

Please provide type hint for the parameter: threshold

"""
Get students scoring above a given threshold.

:param students: List of student dictionaries
:param threshold: Minimum marks for top performers
:return: List of top-performing students
"""
return [s for s in students if s["marks"] >= threshold]


def pass_percentage(students, pass_mark=75):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file other/student_result_processor.py, please provide doctest for the function pass_percentage

Please provide return type hint for the function: pass_percentage. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: students

Please provide type hint for the parameter: pass_mark

"""
Calculate pass percentage.

:param students: List of student dictionaries
:param pass_mark: Minimum marks required to pass
:return: Pass percentage as float
"""
if not students:
return 0.0

passed_count = sum(1 for s in students if s["marks"] >= pass_mark)
return (passed_count / len(students)) * 100


if __name__ == "__main__":
sample_students = [
{"name": "Pranav", "marks": 90},
{"name": "Amit", "marks": 40},
{"name": "Sneha", "marks": 95},
{"name": "Rahul", "marks": 72},
]

passed, failed = separate_students(sample_students)
top = top_performers(sample_students)
percentage = pass_percentage(sample_students)

print("Passed:", passed)
print("Failed:", failed)
print("Top Performers:", top)
print("Pass Percentage:", percentage)