Project Code
import [Link]
from tabulate import tabulate
db = [Link](
host="localhost",
user="root",
password="",database="entrance_exam")
c = [Link]()
[Link]("CREATE DATABASE if not exists entrance_exam")
[Link]("USE entrance_exam")
[Link]("""
CREATE TABLE IF NOT EXISTS students (
student_id INT NOT NULL PRIMARY KEY,
name VARCHAR(60),
dob DATE,
gender VARCHAR(10),
email VARCHAR(70),
phone VARCHAR(20),
address VARCHAR(150)
)
""")
[Link]("""
CREATE TABLE IF NOT EXISTS exams (
exam_id INT NOT NULL PRIMARY KEY,
exam_name VARCHAR(50),
exam_date DATE,
location VARCHAR(80),
eligibility_criteria VARCHAR(40),
application_deadline DATE
)
""")
[Link]("""
CREATE TABLE IF NOT EXISTS applications (
student_id INT NOT NULL,
exam_id INT NOT NULL,
application_date DATE,
status VARCHAR(20) DEFAULT 'Pending',
FOREIGN KEY (student_id) REFERENCES students(student_id),
FOREIGN KEY (exam_id) REFERENCES exams(exam_id)
)
""")
[Link]()
# ---------- USER FUNCTIONS ----------
def register_student():
print("\n=== Student Registration ===")
student_id = input("Student ID: ")
name = input("Full Name: ")
dob = input("Date of Birth (YYYY-MM-DD): ")
gender = input("Gender (M/F): ")
email = input("Email: ")
phone = input("Phone Number: ")
address = input("Address: ")
[Link]("""
INSERT INTO students (student_id, name, dob, gender, email, phone, address)
VALUES (%s,%s,%s,%s,%s,%s,%s)
""", (student_id, name, dob, gender, email, phone, address))
[Link]()
print("Registration Successful!")
def view_exams_user():
print("\n=== Available Exams ===")
[Link]("SELECT * FROM exams")
rows = [Link]()
headers = ["Exam ID", "Exam Name", "Exam Date", "Location",
"Eligibility", "Deadline"]
print(tabulate(rows, headers=headers, tablefmt="grid"))
def apply_for_exam():
print("\n=== Apply For Exam ===")
student_id = input("Your Student ID: ")
exam_id = input("Exam ID: ")
date = input("Application Date (YYYY-MM-DD): ")
[Link]("""
INSERT INTO applications (student_id, exam_id, application_date)
VALUES (%s,%s,%s)
""", (student_id, exam_id, date))
[Link]()
print("Application Submitted Successfully!")
# ---------- ADMIN: STUDENT MANAGEMENT ---------
def view_students():
print("\n=== Students ===")
[Link]("SELECT * FROM students")
rows = [Link]()
headers = ["Student ID", "Name", "DOB", "Gender", "Email", "Phone", "Address"]
print(tabulate(rows, headers=headers, tablefmt="grid"))
def update_student():
student_id = input("Student ID: ")
new_name = input("New Name: ")
new_email = input("New Email: ")
[Link]("UPDATE students SET name=%s, email=%s WHERE student_id=%s",
(new_name, new_email, student_id))
[Link]()
print("Student Updated")
# ---------- ADMIN: EXAM MANAGEMENT ---------
def add_exam():
print("\n=== Add Exam ===")
exam_id = input("Exam ID: ")
name = input("Exam Name: ")
date = input("Exam Date (YYYY-MM-DD): ")
location = input("Location: ")
eligibility = input("Eligibility Criteria: ")
deadline = input("Application Deadline (YYYY-MM-DD): ")
[Link]("""
INSERT INTO exams (exam_id, exam_name, exam_date, location,
eligibility_criteria, application_deadline)
VALUES (%s,%s,%s,%s,%s,%s)
""", (exam_id, name, date, location, eligibility, deadline))
[Link]()
print("Exam Added")
def show_exams():
print("\n=== Exams ===")
[Link]("SELECT * FROM exams")
rows = [Link]()
headers = ["Exam ID", "Exam Name", "Exam Date", "Location",
"Eligibility", "Deadline"]
print(tabulate(rows, headers=headers, tablefmt="grid"))
def update_exam():
exam_id = input("Exam ID: ")
name = input("New Exam Name: ")
date = input("New Exam Date (YYYY-MM-DD): ")
[Link]("UPDATE exams SET exam_name=%s, exam_date=%s WHERE exam_id=
%s",
(name, date, exam_id))
[Link]()
print("Exam Updated")
def delete_exam():
exam_id = input("Exam ID: ")
[Link]("DELETE FROM applications WHERE exam_id=%s", (exam_id,))
[Link]("DELETE FROM exams WHERE exam_id=%s", (exam_id,))
[Link]()
print("Exam Deleted and related applications removed")
# ---------- ADMIN: APPLICATION MANAGEMENT ---------
def show_applications():
print("\n=== Applications ===")
[Link]("""
SELECT a.application_id, [Link], e.exam_name, a.application_date, [Link]
FROM applications a
JOIN students s ON a.student_id=s.student_id
JOIN exams e ON a.exam_id=e.exam_id """)
rows = [Link]()
headers = ["Application ID", "Student Name",
"Exam Name", "Applied Date", "Status"]
print(tabulate(rows, headers=headers, tablefmt="grid"))
def update_application():
app_id = input("Application ID: ")
status = input("New Status: ")
[Link]("UPDATE applications SET status=%s WHERE application_id=%s",
(status, app_id))
[Link]()
print("Application Updated")
# ---------- ADMIN SUB-MENUS ----------
def student_menu():
while True:
print("\n--- Manage Students ---")
print("1. View Students")
print("2. Update Student")
print("3. Back")
choice = input("Your choice: ")
if choice == "1":
view_students()
elif choice == "2":
update_student()
elif choice == "3":
break
else: print("Invalid!")
def exam_menu():
while True:
print("\n--- Manage Exams ---")
print("1. show Exams")
print("2. Add Exam")
print("3. Update Exam")
print("4. Delete Exam")
print("5. Back")
choice = input("Your choice: ")
if choice == "1":
show_exams()
elif choice == "2":
add_exam()
elif choice == "3":
update_exam()
elif choice == "4":
delete_exam()
elif choice == "5":
break
else:
print("Invalid!")
def application_menu():
while True:
print("\n--- Manage Applications ---")
print("1. Show Applications")
print("2. Update Application")
print("3. Back")
choice = input("Your choice: ")
if choice == "1":
show_applications()
elif choice == "2":
update_application()
elif choice == "3":
break
else:
print("Invalid!")
# ---------- USER MENU ----------
def user_menu():
while True:
print("\n====== USER MENU ======")
print("1. Register")
print("2. show Exams")
print("3. Apply for Exam")
print("4. Logout")
choice = input("Your choice: ")
if choice == "1":
register_student()
elif choice == "2":
view_exams_user()
elif choice == "3":
apply_for_exam()
elif choice == "4":
break
else:
print("Invalid choice!")
# ---------- ADMIN MENU ----------
def admin_menu():
while True:
print("\n====== ADMIN MENU ======")
print("1. Manage Students")
print("2. Manage Exams")
print("3. Manage Applications")
print("4. Logout")
choice = input("Your choice: ")
if choice == "1":
student_menu()
elif choice == "2":
exam_menu()
elif choice == "3":
application_menu()
elif choice == "4":
break
else:
print("Invalid!")
# ---------- MAIN MENU ----------
while True:
print("\n===== ENTRANCE EXAM SYSTEM =====")
print("1. Admin")
print("2. User")
print("3. Exit")
role = input("Select Option: ")
if role == "1":
admin_menu()
elif role == "2":
user_menu()
elif role == "3":
print("Exiting...")
break
else:
print("Invalid selection")
[Link]()