IP12 gargi
IP12 gargi
IP12 gargi
Gargi Ojha
XII A
A ABOUT PYTHON
I hope this project meets its intended purpose and proves useful in
educational settings.
Functions Used
addStudent(): Adds a new student record.
updateStudent(): Updates student details.
viewAllRecords(): Displays all records.
searchStudentByID(): Searches by student ID.
searchBySubject(): Finds students by subject.
deleteStudent(): Deletes a student’s record.
averageMarksBySubject(): Calculates subject average marks.
highestScorerBySubject(): Finds highest scorer in a subject.
barChartMarks(): Creates a bar chart of marks.
saveToPDF(): Generates a PDF report.
exportToCSV(): Exports data to CSV.
MENU
1. Add Student
2. Update Student
3. View All Records
4. Search by ID
5. Search by Subject
6. Delete Student
7. Average Marks by Subject
8. Highest Scorer by Subject
9. Count Students by Subject
10. Students Above Threshold
11. Save Subject Data to CSV
12. Export All Data to CSV
13. Bar Chart of Marks
14. Line Graph of Marks
15. Combined Bar Graph
16. Histogram of Marks
17. Save to PDF Report
18. Exit
CODING
import pandas as pd
import matplotlib.pyplot as plt
from fpdf import FPDF
# 15. Combined bar graph for subject averages and highest marks
def combinedBarGraph():
avg_marks = df.groupby("Subject")["Marks"].mean()
highest_marks = df.groupby("Subject")["Marks"].max()
x = avg_marks.index
x_labels = range(len(x))
plt.bar(x_labels, avg_marks, width=0.4, label="Average Marks", color="lightblue",
align="center")
plt.bar([p + 0.4 for p in x_labels], highest_marks, width=0.4, label="Highest Marks",
color="navy")
plt.xticks([p + 0.2 for p in x_labels], x, rotation=45)
plt.xlabel("Subjects")
plt.ylabel("Marks")
plt.title("Subject-wise Average and Highest Marks")
plt.legend()
plt.tight_layout()
plt.show()
# Utility Functions
# Menu
def menu():
while True:
print("\n---- Exam Marks Management ----")
print("1. Add Student")
print("2. Update Student")
print("3. View All Records")
print("4. Search by ID")
print("5. Search by Subject")
print("6. Delete Student")
print("7. Average Marks by Subject")
print("8. Highest Scorer by Subject")
print("9. Count Students by Subject")
print("10. Students Above Threshold")
print("11. Save Subject Data to CSV")
print("12. Export All Data to CSV")
print("13. Bar Chart of Marks")
print("14. Line Graph of Marks")
print("15. Combined Bar Graph")
print("16. Histogram of Marks")
print("17. Save to PDF Report")
print("18. Exit")
Output >>
OPTION 2
Program >>>
# 2. Update an existing student record
def updateStudent():
global df
student_id = int(input("Enter Student ID to update: "))
if student_id in df["Student ID"].values:
name = input("Enter new Student Name (leave blank to keep existing): ")
subject = input("Enter new Subject (leave blank to keep existing): ")
marks = input("Enter new Marks (leave blank to keep existing): ")
if name:
df.loc[df["Student ID"] == student_id, "Name"] = name
if subject:
df.loc[df["Student ID"] == student_id, "Subject"] = subject
if marks:
df.loc[df["Student ID"] == student_id, "Marks"] = int(marks)
print("Student record updated successfully!")
else:
print("Student ID not found.")
Output >>
OPTION 3
Program >>>
# 3. View all student records
def viewAllRecords():
print("\nAll Student Records:")
print(df)
Output >>
OPTION 4
Program >>>
# 4. Search for a student by ID
def searchStudentByID():
student_id = int(input("Enter Student ID to search: "))
record = df[df["Student ID"] == student_id]
if not record.empty:
print("Student Record Found:")
print(record)
else:
print("No record found with the given Student ID.")
Output >>
OPTION 5
Program >>>
# 5. Search for students by subject
def searchBySubject():
subject = input("Enter Subject to search: ")
records = df[df["Subject"].str.lower() == subject.lower()]
if not records.empty:
print("Records Found:")
print(records)
else:
print("No records found for the given subject.")
Output >>
OPTION 6
Program >>>
# 6. Delete a student record
def deleteStudent():
global df
student_id = int(input("Enter Student ID to delete: "))
if student_id in df["Student ID"].values:
df = df[df["Student ID"] != student_id]
print("Record deleted successfully!")
else:
print("Student ID not found.")
Output >>
OPTION 7
Program >>>
# 7. Calculate average marks for a subject
def averageMarksBySubject():
subject = input("Enter Subject to calculate average marks: ")
avg_marks = df[df["Subject"].str.lower() == subject.lower()]["Marks"].mean()
if not pd.isna(avg_marks):
print(f"Average Marks for {subject}: {avg_marks:.2f}")
else:
print("No data available for the given subject.")
Output >>
OPTION 8
Program >>>
# 8. Find the highest scorer in a subject
def highestScorerBySubject():
subject = input("Enter Subject to find the highest scorer: ")
records = df[df["Subject"].str.lower() == subject.lower()]
if not records.empty:
top_scorer = records.loc[records["Marks"].idxmax()]
print(f"Highest Scorer in {subject}:")
print(top_scorer)
else:
print("No data available for the given subject.")
Output >>
OPTION 9
Program >>>
Output >>
OPTION 11
Program >>>
# 11. Save data for a specific subject to a CSV file
def saveSubjectData():
subject = input("Enter Subject: ")
records = df[df["Subject"].str.lower() == subject.lower()]
if not records.empty:
filename = f"{subject}_data.csv"
records.to_csv(filename, index=False)
print(f"Data for {subject} saved to {filename}.")
else:
print("No data found for the given subject.")
Output >>
OPTION 12
Program >>>
# 12. Export entire data to CSV
def exportToCSV():
global df
df.to_csv("ExamData.csv", index=False)
print("Data saved to ExamData.csv.")
Output >>
OPTION 13
Program >>>
# 13. Bar chart of marks by student
def barChartMarks():
df.plot(x="Name", y="Marks", kind="bar", title="Marks Bar Chart", color="navy")
plt.xlabel("Student Name")
plt.ylabel("Marks")
plt.xticks(rotation=45)
plt.show()
Output >>
OPTION 14
Program >>>
# 14. Line graph of student marks
def lineGraphMarks():
df.sort_values("Marks", inplace=True)
plt.plot(df["Name"], df["Marks"], marker="o", linestyle="-", color="green", label="Marks")
plt.title("Student Marks Line Graph")
plt.xlabel("Student Name")
plt.ylabel("Marks")
plt.xticks(rotation=45)
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
Output >>
OPTION 15
Program >>>
# 15. Combined bar graph for subject averages and highest marks
def combinedBarGraph():
avg_marks = df.groupby("Subject")["Marks"].mean()
highest_marks = df.groupby("Subject")["Marks"].max()
x = avg_marks.index
x_labels = range(len(x))
plt.bar(x_labels, avg_marks, width=0.4, label="Average Marks", color="lightblue",
align="center")
plt.bar([p + 0.4 for p in x_labels], highest_marks, width=0.4, label="Highest Marks",
color="orange")
plt.xticks([p + 0.2 for p in x_labels], x, rotation=45)
plt.xlabel("Subjects")
plt.ylabel("Marks")
plt.title("Subject-wise Average and Highest Marks")
plt.legend()
plt.tight_layout()
plt.show()
Output >>
OPTION 16
Program >>>
# 16. Histogram of marks distribution
def histogramMarks():
df["Marks"].plot(kind="hist", bins=5, title="Marks Distribution", color="orange")
plt.xlabel("Marks")
plt.ylabel("Frequency")
plt.show()
Output >>
OPTION 17
Program >>>
Output >>
OPTION 18
Program >>>
elif choice == 18:
print("Exiting...")
break
Output >>
CSV
BIBLIOGRAPHY
www.google.com
www.wikipedia.con
www.python.org/help
NCERT Informatics Practices (2024-25)
CLASS XII