Information Practice ProjectRushda
Information Practice ProjectRushda
Student Profile
Name: - Rushda
Class: - XII
Principal’s Signature
INDEX
➢Acknowledgement
➢Introduction
o Objective
o Key features
o Benefits
➢Source code
➢Output
o Main Login Menu
o User Dashboard
o Admin Dashboard
o Adding New Column
o Add New Student Record
o Display all the Records
o Delete Student Record
o Export to csv
o Graphical analysis (Hobby vs Percentage)
➢Bibliography
ACKNOWLEDGEMENT
Sincerely,
Rushda
Class 12
Introduction
def initialize_db():
"""Initialize the SQLite database and create the table if it
doesn't exist."""
conn = sqlite3.connect("student_records.db")
cursor = conn.cursor()
# Create the 'students' table if it does not already exist
cursor.execute('''CREATE TABLE IF NOT EXISTS students (
Roll_No INTEGER PRIMARY KEY,
Name TEXT,
Hobby TEXT,
Address TEXT,
Gender TEXT,
Percentage REAL,
Age INTEGER,
Weight REAL)''')
conn.commit()
conn.close()
def fetch_all_records():
"""Fetch all records from the database into a DataFrame."""
conn = sqlite3.connect("student_records.db")
# Use pandas to read SQL query results into a DataFrame
df = pd.read_sql_query("SELECT * FROM students", conn,
index_col="Roll_No")
conn.close()
return df
def delete_column():
"""Inform the user that SQLite does not support dropping
columns."""
print("SQLite does not support deleting columns directly. You
may need to create a new table.")
def rename_column():
"""Rename a column in the database table."""
print("SQLite does not support renaming columns directly.")
def add_student():
"""Add a new student's record."""
# Prompt user for all student details
roll_no = int(input("Enter roll number: "))
name = input("Enter name: ")
hobby = input("Enter hobby: ")
address = input("Enter address: ")
gender = input("Enter gender (M/F): ")
percentage = float(input("Enter percentage: "))
age = int(input("Enter age: "))
weight = float(input("Enter weight: "))
# Insert new record into the 'students' table
query = '''INSERT INTO students (Roll_No, Name, Hobby,
Address, Gender, Percentage, Age, Weight)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)'''
execute_query(query, (roll_no, name, hobby, address, gender,
percentage, age, weight))
print("Student record added successfully!")
def delete_student():
"""Delete a student's record by roll number."""
roll_no = int(input("Enter roll number to delete: "))
query = "DELETE FROM students WHERE Roll_No = ?"
execute_query(query, (roll_no,))
print("Student record deleted successfully!")
def display_students():
"""Display all student records."""
df = fetch_all_records()
print("\nStudent Records:\n")
print(df.to_markdown()) # Display DataFrame in a tabular
format
def sort_students():
"""Sort student records by a specified column."""
df = fetch_all_records()
print("Columns: ", df.columns.tolist())
col = input("Enter column to sort by: ")
if col in df.columns:
order = input("Ascending or Descending? (A/D):
").strip().upper()
ascending = order == 'A'
# Display the sorted DataFrame
print(df.sort_values(by=col,
ascending=ascending).to_markdown())
else:
print("No such column exists.")
def graphical_analysis():
"""Display graphical analysis of hobby vs percentage."""
df = fetch_all_records()
if 'Hobby' in df.columns and 'Percentage' in df.columns:
# Group data by 'Hobby' and calculate the average
percentage
grouped = df.groupby('Hobby')['Percentage'].mean()
# Plot a bar chart of hobbies vs average percentage
grouped.plot(kind='bar', title='Hobby vs Average Percentage')
plt.xlabel('Hobby')
plt.ylabel('Average Percentage')
plt.show()
else:
print("Columns 'Hobby' and 'Percentage' are required for this
analysis.")
def export_to_csv():
"""Export all student records to a CSV file."""
df = fetch_all_records()
filename = input("Enter the filename to export (e.g.,
students.csv): ")
try:
# Save DataFrame to a CSV file
df.to_csv(filename)
print(f"Records successfully exported to {filename}.")
except Exception as e:
print(f"Error exporting records: {e}")
def admin_panel():
"""Admin functionalities."""
while True:
print("\nAdmin Panel:")
print("1. Add a new column")
print("2. Delete a column")
print("3. Rename a column")
print("4. Add a new student record")
print("5. Delete a student record")
print("6. Display all records")
print("7. Sort records by a column")
print("8. Graphical analysis (Hobby vs Percentage)")
print("9. Export records to CSV")
print("10. Exit")
if choice == 1:
add_column()
elif choice == 2:
delete_column()
elif choice == 3:
rename_column()
elif choice == 4:
add_student()
elif choice == 5:
delete_student()
elif choice == 6:
display_students()
elif choice == 7:
sort_students()
elif choice == 8:
graphical_analysis()
elif choice == 9:
export_to_csv()
elif choice == 10:
print("Exiting Admin Panel.")
break
else:
print("Invalid choice. Try again.")
def user_panel():
"""User functionalities."""
while True:
print("\nUser Panel:")
print("1. Display all records")
print("2. Display records sorted by a column")
print("3. Graphical analysis (Hobby vs Percentage)")
print("4. Exit")
if choice == 1:
display_students()
elif choice == 2:
sort_students()
elif choice == 3:
graphical_analysis()
elif choice == 4:
print("Exiting User Panel.")
break
else:
print("Invalid choice. Try again.")
def main():
"""Main function to run the program."""
initialize_db() # Initialize the database on startup
admin_password = "@aryankushwaha" # Hardcoded admin
password
print("\nWelcome to Student Record Management System")
while True:
print("\nLogin as:")
print("1. Admin")
print("2. User")
print("3. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
# Prompt for admin password
password = input("Enter Admin Password: ")
if password == admin_password:
admin_panel()
else:
print("Incorrect password.")
elif choice == 2:
user_panel()
elif choice == 3:
print("Exiting system. Goodbye!")
break
else:
print("Invalid choice. Try again.")
if __name__ == "__main__":
main()
Output
User Panel :
Admin Panel:
Adding New Column