0% found this document useful (0 votes)
38 views15 pages

Student DBMS Report

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

Student DBMS Report

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

KONGU ENGINEERING COLLEGE

(Autonomous)
PERUNDURAI ERODE – 638 060

Student Database Management System

A Project Report
submitted by

Giridharan S
22ITR025
Ashoknirmal P S
22ITR009
Bharath M
22ITR012

PYTHON PROGRAMMING AND FRAMEWORKS ( 22ITT32 )


DEPARTMENT OF INFORMATION TECHNOLOGY
CODING :
main.py
import personalinfo as per
import academic as aca
while True:
print("(1) Personal Details")
print("(2) Academic Details")
print("(3) Display all details")
print("(4) Display report for single data \n")
s=input("Enter any one Option : ")
print("\n")
if s=='1':
per.choose()
elif s=='2':
aca.fin()
elif s=='3':
per.show_all()
aca.display_all_records()
elif s=='4':
r=input("Enter Roll number to search : ")
per.show_particular(r)
aca.display_data1(r)
else:
print("Please Enter a valid Input.")

personalinfo.py

import mysql.connector as mc
from prettytable import PrettyTable

mydb = mc.connect(
host = "localhost",
user = "root",
password = "********",
database = "stu"
)
cur = mydb.cursor()

table_name = "details"

all_table = PrettyTable()
all_table.field_names = ["Roll Number", "Name", "Gender", "Date Of Birth",
"Mobile Number", "Email Id", "Department", "Year of Study"]

one_table = PrettyTable()
one_table.field_names = ["Roll Number", "Name", "Gender", "Date Of Birth",
"Mobile Number", "Email Id", "Department", "Year of Study"]

global x
x=1
def option(s):
match s:
case '1':
insert_row()
case '2':
print("(1) All Details ")
print("(2) Particular Details ")
opt = input('Enter your choice : ')
if opt == '1':
show_all()
elif opt == '2':
show_particular(input("Enter Roll Number to search : "))
else:
print("Invalid choice.")
case '3':
update_one(input("Enter Roll number to update : "))
case '4':
print("(1) Delete whole table ")
print("(2) Delete particular Data ")
ch = input('Enter your choice : ')
if ch == '1':
delete_table(table_name)
elif ch == '2':
delete_one(input("Enter Roll number to delete : "))
else:
print("Invalid choice.")
case '5':
print("Exited")
return

def create_table():
try:
cre_det_tab = (f"CREATE TABLE IF NOT EXISTS {table_name} (Roll
varchar(10) PRIMARY KEY, Name varchar(20), Gender varchar(10), DOB
varchar(10), MobileNumber varchar(13), EmailID varchar(50), Department
varchar(20), YearOfStudy varchar(10))")
cur.execute(cre_det_tab)
mydb.commit()
except mc.Error as e:
print("Error in creating a table as : ", e)

def insert_row():
ins = (f"INSERT INTO {table_name} (Roll, Name, Gender, DOB, MobileNumber,
EmailID, Department, YearOfStudy) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)")
roll = int(input('Enter Roll Number: '))
name = input('Enter Name : ')
gender = input('Enter Gender : ')
dob = input('Enter Date of Birth : ')
mob = input('Enter Mobile Number : ')
email = input('Enter Email ID : ')
dept = input('Enter Department : ')
year = input('Enter Year of Study : ')
val = (roll, name, gender, dob, mob, email, dept, year)
all_table.add_row(val)
cur.execute(ins, val)
mydb.commit()
print("Successfully inserted.")

def add_to_all():
try:
sel = f"SELECT * FROM {table_name}"
cur.execute(sel)
rows = cur.fetchall()
if len(rows) > 0:
print("\nPersonal Details : \n")
for row in rows:
all_table.add_row([row[0], row[1], row[2], row[3], row[4],
row[5], row[6], row[7]])
except mc.Error as e:
print("Error in add all: ",e)

def show_all():
try:
sel = f"SELECT * FROM {table_name}"
cur.execute(sel)
rows = cur.fetchall()
global x
if len(rows) > 0:
print("\nPersonal Details : \n")
if x==1:
for row in rows:
all_table.add_row([row[0], row[1], row[2], row[3], row[4],
row[5], row[6], row[7]])
print(all_table)
else:
print("No data found.")
except:
print("Table not found.")
finally:
x+=1
def show_particular(r):
try:
sel = f"SELECT * FROM {table_name} WHERE Roll=%s"
cur.execute(sel, (r,))
res = cur.fetchone()
if res!=None:
one_table.clear_rows()
one_table.add_row([res[0], res[1], res[2], res[3], res[4], res[5],
res[6], res[7]])
print(one_table)
else:
print("Data not Found.\n")
except:
print("Table not found.")

def update_one(roll):
nme = input('\nEnter New Name : ')
gndr = input('Enter New Gender : ')
dOB = input('Enter new DOB : ')
mblNum = input('Enter New Mobile Number : ')
emlId = input('Enter New Email Id : ')
dept = input('Enter New Department : ')
year = input('Enter New Year of Study : ')
upd = f"UPDATE {table_name} SET Name=%s, Gender=%s, DOB=%s,
MobileNumber=%s, EmailID=%s, Department=%s, YearOfStudy=%s WHERE Roll=%s"
val = (nme, gndr, dOB, mblNum, emlId, dept, year, roll)
cur.execute(upd, val)
mydb.commit()
print("Successfully Updated.\n")

def delete_table(tab_name):
a = f"DROP TABLE IF EXISTS {tab_name}"
cur.execute(a)
mydb.commit()
print("Table has been deleted.\n")

def delete_one(roll):
sel = f"SELECT * FROM {table_name} WHERE Roll={roll}"
cur.execute(sel)
rec = cur.fetchone()
if rec:
a = f"DELETE FROM {table_name} WHERE Roll=%s"
cur.execute(a, (roll,))
mydb.commit()
print("Deleted Successfully.\n")
else:
print("No data found in the Record.\n")
try:

def choose():
while True:
create_table()
print("(1) Insert New Data")
print("(2) Display")
print("(3) Update")
print("(4) Delete")
print("(5) Exit")
op = (input("Enter your option: "))
option(op)
except mc.Error as e:
print("error in main last : ",e)

academic.py

import mysql.connector
from prettytable import PrettyTable
from tabulate import tabulate

try:
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="********",
database="stu"
)
cursor = mydb.cursor()
except mysql.connector.Error as err:
print(f"Error in connection: {err}")
def create_table():
cursor.execute("""
create table if not exists marks (
Roll_Number INT PRIMARY KEY,
Name VARCHAR(255),Subject_1 VARCHAR(50),
Subject_2 VARCHAR(50),Subject_3 VARCHAR(50),
Subject_4 VARCHAR(50),Subject_5 VARCHAR(50),
Subject_6 VARCHAR(50),Total_Credits INT,
GPA FLOAT,CGPA FLOAT,Outcome VARCHAR(10))
""")

def calculate_gpa(subjects,total_cre):
total_credits = 0
mrks = 0
for credit_grade in subjects:
credit, grade = credit_grade.split(',')
try:
total_credits += int(credit)
mrks += int(credit) * get_grade_value(grade)
except ValueError:
print(f"Invalid grade value: {grade}.")
if total_credits == 0:
return 0
elif total_credits!=total_cre:
return -1
gpa = mrks / total_credits
return round(gpa, 2)

def get_grade_value(grade):
grade_values = {'O': 10, 'A+': 9, 'A': 8, 'B+': 7, 'B': 6, 'C': 5, 'U': 0}
return grade_values.get(grade.upper(), 0)

def calculate_cgpa( roll_number, current_gpa):


try:
cursor.execute("SELECT CGPA FROM marks WHERE Roll_Number=%s",
(roll_number,))
previous_cgpa = cursor.fetchone()
if previous_cgpa:
new_cgpa = (current_gpa + previous_cgpa[0]) / 2
else:
new_cgpa = current_gpa
return round(new_cgpa, 2)
except mysql.connector.Error as err:
print(f"Error in cgpa calc: {err}")
return None

def calculate_pf(subjects):
pass_gra = {'O': 100, 'A+': 90, 'A': 80, 'B+': 70, 'B': 60, 'C': 50, 'U':
0}
if any(grade.split(',')[1].upper() == 'U' for grade in subjects):
return "Arrear"
else:
valid_subjects = [grade for grade in subjects if
grade.split(',')[1].upper() != 'U']
mrks = sum(pass_gra[grade.split(',')[1].upper()] *
int(grade.split(',')[0]) for grade in valid_subjects)
total_credits = sum(int(grade.split(',')[0]) for grade in
valid_subjects)
average_score = mrks / total_credits
return "Pass" if average_score >= 50 else "Arrear"

def insert_data():
try:
roll_number = int(input("Enter Roll Number: "))
name = input("Enter Name: ")
subjects = []
total_credits = int(input("Enter Total Number of Credits: "))
for i in range(1, 7):
subject_input = input(f"Enter marks for Subject {i} (format:
credit,grade): ")
subjects.append(subject_input)
gpa = calculate_gpa(subjects,total_credits)
cgpa = calculate_cgpa( roll_number, gpa)
pf = calculate_pf(subjects)
cursor.execute("""
INSERT INTO marks (
Roll_Number, Name, Subject_1, Subject_2, Subject_3,
Subject_4, Subject_5, Subject_6, Total_Credits, GPA, CGPA,
Outcome
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
""", (roll_number, name,) + tuple(subjects) + (total_credits, gpa,
cgpa, pf))
print("Data inserted successfully!")
except mysql.connector.Error as err:
print(f"Error in insert: {err}")

def update_data():
try:
roll_number = int(input("Enter Roll Number: "))
subjects = []
cursor.execute("SELECT * FROM marks WHERE Roll_Number=%s",
(roll_number, ))
existing_record = cursor.fetchone()
if existing_record:
total_credits = int(input("Enter Total Number of Credits: "))
for i in range(1, 7):
subject_input = input(f"Enter updated marks for Subject {i}
(format: credit,grade): ")
subjects.append(subject_input)
gpa = calculate_gpa(subjects,total_credits)
if gpa!=-1:
cgpa = calculate_cgpa( roll_number, gpa)
pf = calculate_pf(subjects)
cursor.execute("""
UPDATE marks
SET Subject_1=%s, Subject_2=%s, Subject_3=%s,
Subject_4=%s, Subject_5=%s, Subject_6=%s,
Total_Credits=%s, GPA=%s, CGPA=%s, Outcome=%s
WHERE Roll_Number=%s
""", tuple(subjects) + (total_credits, gpa, cgpa, pf,
roll_number))
print("Data updated successfully!")
else:
print("Number of credits not matching.")
else:
print("Name or Roll Number not matching. No data updated.")
except mysql.connector.Error as err:
print(f"Error in update: {err}")

def display_data( roll_number):


try:
cursor.execute("""
SELECT * FROM marks
WHERE Roll_Number=%s
""", (roll_number,))
data = cursor.fetchone()
if data:
table_data = [
["Roll Number", data[0]],
["Name", data[1]],
["Total Credits", data[8]],
["Subject 1", data[2]],
["Subject 2", data[3]],
["Subject 3", data[4]],
["Subject 4", data[5]],
["Subject 5", data[6]],
["Subject 6", data[7]],
["Current Semester GPA", data[9]],
["CGPA up to Current Semester", data[10]],
["Pass/Fail", data[11]],
]
table = tabulate(table_data, tablefmt="grid")
print(table)
else:
print("No data found for the given roll number and name.")
except mysql.connector.Error as err:
print(f"Error in display: {err}")

def display_data1( roll_number):


try:
cursor.execute("""
SELECT * FROM marks
WHERE Roll_Number=%s
""", (roll_number,))
data = cursor.fetchone()
if data:
table_data = [
["Total Credits", data[8]],
["Subject 1", data[2]],
["Subject 2", data[3]],
["Subject 3", data[4]],
["Subject 4", data[5]],
["Subject 5", data[6]],
["Subject 6", data[7]],
["Current Semester GPA", data[9]],
["CGPA up to Current Semester", data[10]],
["Pass/Fail", data[11]],
]
table = tabulate(table_data, tablefmt="grid")
print(table)
else:
print("No data found for the given roll number and name.")
except mysql.connector.Error as err:
print(f"Error in display: {err}")

def display_all_records():
try:
cursor.execute("SELECT * FROM marks")
data = cursor.fetchall()
if data:
print("Academic Details : ")
table = PrettyTable()
table.field_names = ["Roll Number", "Name", "Subject 1", "Subject
2", "Subject 3", "Subject 4", "Subject 5", "Subject 6", "Total Credits",
"GPA", "CGPA", "Outcome"]
for row in data:
table.add_row(row)
print(table)
else:
print("No records found.")
except mysql.connector.Error as err:
print(f"Error in display_all_records: {err}")

def delete_data():
try:
roll_number = int(input("Enter Roll Number to delete: "))
cursor.execute("SELECT * FROM marks WHERE Roll_Number=%s",
(roll_number,))
existing_record = cursor.fetchone()
if existing_record:
cursor.execute("DELETE FROM marks WHERE Roll_Number=%s",
(roll_number,))
print(f"Record for Roll Number {roll_number} deleted
successfully!")
else:
print(f"No record found for Roll Number {roll_number}.")
except mysql.connector.Error as err:
print(f"Error in delete: {err}")

def choose():
print("\n\n(1) Insert New Data")
print("(2) Update Existing Data")
print("(3) Display Particular Record")
print("(4) Display all Records")
print("(5) Delete Record by Roll Number")
print("(6) Exit")

def fin():
try:
create_table()
while True:
choose()
option = input("\nEnter any one option: ")
match option:
case '1':
insert_data()
case '2':
update_data()
case '3':
roll_number = int(input("Enter Roll Number: "))
display_data(roll_number)
case '4':
display_all_records()
case '5':
delete_data()
case '6':
print("Exited")
break
case _:
print("Invalid option. Please choose a valid option.")
mydb.commit()
except mysql.connector.Error as err:
print(f"Error in main: {err}")
OUTPUT :

You might also like