0% found this document useful (0 votes)
7 views6 pages

Source Code

The document is a Python script for analyzing student performance across various subjects. It includes functions to calculate averages, recommend improvements, and display individual and class summaries. The script processes a dataset of students and their scores, providing insights into overall performance and areas needing attention.

Uploaded by

anilalbin2005
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

Source Code

The document is a Python script for analyzing student performance across various subjects. It includes functions to calculate averages, recommend improvements, and display individual and class summaries. The script processes a dataset of students and their scores, providing insights into overall performance and areas needing attention.

Uploaded by

anilalbin2005
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

# -------------------------------

# Dataset

# -------------------------------

students = [

{"name": "Alice", "Math": 92, "Science": 88, "English": 95, "Physics": 78, "History": 85},

{"name": "Bob", "Math": 74, "Science": 65, "English": 70, "Physics": 60, "History": 68},

{"name": "Carlos", "Math": 95, "Science": 91, "English": 89, "Physics": 93, "History": 90},

{"name": "Diana", "Math": 55, "Science": 48, "English": 62, "Physics": 50, "History": 58},

{"name": "Eve", "Math": 80, "Science": 76, "English": 83, "Physics": 79, "History": 72},

{"name": "Frank", "Math": 67, "Science": 72, "English": 65, "Physics": 88, "History": 70},

{"name": "Grace", "Math": 88, "Science": 84, "English": 91, "Physics": 85, "History": 87},

subjects = ["Math", "Science", "English", "Physics", "History"]

print(f"Dataset loaded: {len(students)} students, {len(subjects)} subjects")

def calculate_average(marks_list):

"""Return the average of a list of marks."""

return sum(marks_list) / len(marks_list)

def get_recommendation(score):

"""Return performance recommendation."""

if score >= 85:

return "Excellent Performance"

elif score >= 70:


return "Good Performance"

else:

return "Needs Improvement"

def student_overall_average(student):

"""Calculate overall average of one student."""

marks = [student[sub] for sub in subjects]

return calculate_average(marks)

def subject_averages():

"""Calculate average marks for each subject."""

averages = {}

for sub in subjects:

all_marks = [s[sub] for s in students]

averages[sub] = calculate_average(all_marks)

return averages

def weakest_subject(student):

"""Return subject with lowest score."""

return min(subjects, key=lambda sub: student[sub])

def find_top_performer():

"""Find student with highest average."""

return max(students, key=student_overall_average)


def find_lowest_scorer():

"""Find student with lowest average."""

return min(students, key=student_overall_average)

def students_needing_improvement():

"""Return students with average below 70."""

return [s for s in students if student_overall_average(s) < 70]

def print_divider(char="-", width=55):

print(char * width)

def display_subject_analysis():

"""Display subject-wise statistics."""

print("\nSUBJECT-WISE CLASS ANALYSIS")

print_divider()

averages = subject_averages()

for sub in subjects:

all_marks = [s[sub] for s in students]

class_avg = averages[sub]

high_score = max(all_marks)

low_score = min(all_marks)
top_student = next(s["name"] for s in students if s[sub] == high_score)

low_student = next(s["name"] for s in students if s[sub] == low_score)

print(f"\n{sub}")

print(f"Class Average : {class_avg:.1f}")

print(f"Highest Score : {high_score} ({top_student})")

print(f"Lowest Score : {low_score} ({low_student})")

def display_individual_report():

"""Display report card of every student."""

print("\nINDIVIDUAL STUDENT REPORT")

print_divider()

for student in students:

overall = student_overall_average(student)

weak = weakest_subject(student)

recommendation = get_recommendation(overall)

print(f"\nStudent : {student['name']}")

for sub in subjects:

print(f"{sub}: {student[sub]}")

print(f"Average : {overall:.1f}")

print(f"Status : {recommendation}")

print(f"Focus Area : {weak}")


def display_class_summary():

"""Display overall class summary."""

top = find_top_performer()

lowest = find_lowest_scorer()

needs_help = students_needing_improvement()

print("\nCLASS PERFORMANCE SUMMARY")

print_divider()

print(f"Top Performer : {top['name']} ({student_overall_average(top):.1f})")

print(f"Lowest Scorer : {lowest['name']} ({student_overall_average(lowest):.1f})")

print("\nStudents Needing Improvement:")

if needs_help:

for s in needs_help:

print(f"{s['name']} - Average: {student_overall_average(s):.1f}")

else:

print("None")

def display_subject_recommendations():

"""Recommend subject needing most attention."""

averages = subject_averages()

weakest_sub = min(averages, key=[Link])

print("\nCLASS LEVEL RECOMMENDATION")


print_divider()

for sub, avg in [Link]():

print(f"{sub}: {avg:.1f}")

print(f"\nRecommendation: Focus more on {weakest_sub}")

def main():

print("=" * 55)

print("SMART STUDENT PERFORMANCE ANALYSIS SYSTEM")

print("=" * 55)

display_subject_analysis()

display_individual_report()

display_class_summary()

display_subject_recommendations()

print("\nAnalysis Complete!")

main()

You might also like