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

Exam and Student Management System

The document contains two programs: the first is a simple exam management system that allows users to add, display, delete, and view upcoming exams using a stack data structure. The second program connects to a MySQL database to manage student records, including adding, updating, deleting, and searching for students. Both programs include user interaction through a menu-driven interface.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Exam and Student Management System

The document contains two programs: the first is a simple exam management system that allows users to add, display, delete, and view upcoming exams using a stack data structure. The second program connects to a MySQL database to manage student records, including adding, updating, deleting, and searching for students. Both programs include user interaction through a menu-driven interface.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PROGRAM 11

stack = []
def add_exam():
name = input("Enter exam name: ")
subject = input("Enter subject: ")
date = input("Enter date: ")
[Link]({'name': name, 'subject': subject, 'date': date})
print("Exam added")
def display_exams():
if stack == []:
print("No exams")
else:
for exam in stack:
print(exam['name'], exam['subject'], exam['date'])
def delete_exam():
if stack == []:
print("No exams to delete")
else:
exam = [Link]()
print("Deleted:", exam['name'])

def view_exam():
if stack == []:
print("No upcoming exams")
else:
exam = stack[-1]
print(exam['name'], exam['subject'], exam['date'])
while True:
print(‘’’
\n1. Add exam
2. Display exams
3. Delete exam
4. View upcoming exam
5. Exit’’’)
choice = input("Enter choice: ")
if choice == '1':
add_exam()
elif choice == '2':
display_exams()
elif choice == '3':
delete_exam()
elif choice == '4':
view_exam()
elif choice == '5':
break
else:
print("Invalid choice")

Program 12
import [Link]
def connect_to_db():
try:
conn = [Link](
host="localhost",
user="root",
password=’IISM@123’)
cursor = [Link]()
[Link]("CREATE DATABASE IF NOT EXISTS School")
[Link]()
[Link]()
conn = [Link](
host="localhost",
user="root",
password="IISM@123",
database="School")
return conn
except [Link] as err:
print("Error: ", err)
return None
def create_table():
conn = connect_to_db()
if conn:
cursor = [Link]()
[Link]('''CREATE TABLE IF NOT EXISTS students (
StudentID INT AUTO_INCREMENT PRIMARY KEY,
StudentName VARCHAR(100),
Age INT,
Grade VARCHAR(10))''')
[Link]()
[Link]()
[Link]()
def add_student():
conn = connect_to_db()
if conn:
cursor = [Link]()
name = input("Enter student name: ")
try:
age = int(input("Enter student age: "))
except ValueError:
print("Invalid age. Please enter a valid integer.")
[Link]()
[Link]()
return
grade = input("Enter student grade: ")
[Link]('''INSERT INTO students (StudentName, Age, Grade) VALUES (%s,
%s, %s)''', (name, age, grade))
[Link]()
print("Student record added successfully!")
[Link]()
[Link]()
def delete_student():
conn = connect_to_db()
if conn:
cursor = [Link]()
student_id = int(input("Enter student ID to delete: "))
[Link]('''DELETE FROM students WHERE StudentID = %s''', (student_id,))
[Link]()
print("Student ID ", student_id, "deleted.")
[Link]()
[Link]()
def update_grade():
conn = connect_to_db()
if conn:
cursor = [Link]()
student_id = int(input("Enter student ID to update: "))
new_grade = input("Enter new grade: ")
[Link]('''UPDATE students SET Grade = %s WHERE StudentID = %s''',
(new_grade, student_id))
[Link]()
print("Student ID ", student_id, "'s grade updated to ", new_grade)
[Link]()
[Link]()
def search_student():
conn = connect_to_db()
if conn:
cursor = [Link]()
student_name = input("Enter student name to search: ")
[Link]('''SELECT * FROM students WHERE StudentName = %s''',
(student_name,))
student = [Link]()
if student:
print("Student Found - ID: ", student[0], "Name: ", student[1], "Age: ", student[2],
"Grade: ", student[3])
else:
print("No student found with the name ", student_name)
[Link]()
[Link]()
def menu():
create_table()
while True:
print("\nMenu:")
print("1. Add a new student record")
print("2. Update a student's grade")
print("3. Delete a student record")
print("4. Search for a student by name")
print("5. Exit")
choice = input("Enter your choice (1-5): ")
if choice == '1':
add_student()
elif choice == '2':
update_grade()
elif choice == '3':
delete_student()
elif choice == '4':
search_student()
elif choice == '5':
print("Exiting program...")
break
else:
print("Invalid choice, please try again.")
menu()

You might also like