0% found this document useful (0 votes)
21 views7 pages

Ip Practical

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

Ip Practical

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

SOURCE CODE

import pandas as pd
import matplotlib.pyplot as plt

# Initialize an empty DataFrame for student data


columns = ['Student ID', 'Name', 'Age', 'Grade', 'Email']
students_df = pd.DataFrame(columns=columns)

def add_student():
student_id = int(input("Enter Student ID: "))
name = input("Enter Name: ")
age = int(input("Enter Age: "))
grade = input("Enter Grade: ")
email = input("Enter Email: ")
new_student = pd.DataFrame({
'Student ID': [student_id],
'Name': [name],
'Age': [age],
'Grade': [grade],
'Email': [email]})
global students_df
students_df_n = students_df.dropna(axis=1, how= 'all')
students_df=pd.concat([students_df_n, new_student],axis=0,
ignore_index=True)
print(f"Student {name} added successfully!")

def update_student():
student_id = int(input("Enter Student ID to update: "))
index = students_df[students_df['Student ID'] ==
student_id].index
if not index.empty:
for key in ['Name', 'Age', 'Grade', 'Email']:
value = input(f"Enter new value for {key} (or press Enter to
skip): ") if value:
if key == 'Age':
value = int(value)
students_df.at[index[0], key] = value
print(f"Student ID {student_id} updated successfully!")
else:
def delete_student():
student_id = int(input("Enter Student ID to delete: "))

global students_df
index = students_df[students_df['Student ID'] ==
student_id].index
if not index.empty:
students_df = students_df.drop(index)
students_df.reset_index(drop=True, inplace=True)
print(f"Student ID {student_id} deleted
successfully!")
else:
print(f"Student ID {student_id} not found.")
def view_student():
student_id = int(input("Enter Student ID to
view: ")) student =
students_df[students_df['Student ID'] ==
student_id]
if not student.empty:
print(student)
else:
print(f"Student ID {student_id} not
found.")

def view_all_students():
print(students_df)
def display_bar_chart():
if not students_df.empty:
plt.figure(figsize=(10, 6))
plt.bar(students_df['Name'], students_df['Age'],
color='skyblue')
plt.xlabel('Student Name')
plt.ylabel('Age')
plt.title('Student Age Distribution')
plt.xticks(rotation=45, ha='right')
plt.tight_layout()
plt.show()
else:
print("No student data available to display.")
def menu():
while True:
print("\nStudent Management System")
print("1. Add Student")
print("2. Update Student")
print("3. Delete Student")
print("4. View Student")
print("5. View All Students")
print("6. Display Age Bar Chart")
print("7. Exit")
choice = input("Enter your choice (1-7): ")
if choice == '1':
add_student()
elif choice == '2':
update_student()
elif choice == '3':
delete_student()
elif choice == '4':
view_student()
elif choice == '5':
view_all_students()
elif choice == '6':
display_bar_chart()
elif choice == '7':
print("Exiting the program. Goodbye!")
break
else:
print("Invalid choice. Please enter a number between 1 and 7.")

# Run the menu


if _name_ == "_main_":
menu()

You might also like