Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
303 views

Source Code in Python

This Python code defines functions for a report card management system that allows users to add, modify, search, and view student records and marks stored in a MySQL database. The functions include adding/modifying student and mark details, searching by admission number, name, or term marks, and generating a report for a single student term. The code connects to a MySQL database called "report_card" to perform CRUD operations on tables for students and marks.
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)
303 views

Source Code in Python

This Python code defines functions for a report card management system that allows users to add, modify, search, and view student records and marks stored in a MySQL database. The functions include adding/modifying student and mark details, searching by admission number, name, or term marks, and generating a report for a single student term. The code connects to a MySQL database called "report_card" to perform CRUD operations on tables for students and marks.
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
You are on page 1/ 15

Source Code in Python:

"""
COMPUTER SCIENCE PROJECT
"REPORT CARD MANAGEMENT SYSTEM"
SUBMITTED BY :- MRIGANK YASHVARDHAN
CLASS :- XII A2

"""

#Importing required module:-


import mysql.connector
from prettytable import PrettyTable

#**********************************************************************************

#Global variable for report


school_name = 'Oxford Model Senior Secondary School'
school_address = 'Pac Road Shyam Nagar Kanpur Uttarpradesh'
school_email = 'oxfordmodel@gmail.com'
school_phone = '+91 9456387250'

#**********************************************************************************

# 1. Clear function :- To make apppear screen is clear (VISUALLY)


def clear():
for _ in range(65):
print()

#**********************************************************************************

# 2. Defining the ADD_STUDENT FUNCTION (Add the students details to the existing
database)

def add_student():
# Establishing a connection to the database
conn = mysql.connector.connect(
host='localhost',
database='report_card',
user='root',
password='kalpit369'
)

# Creating a cursor object


cursor = conn.cursor()

#Calling Clear function


clear()

print('Add New Student Screen')


print('-'*120)

#Prompt User to Input the required Details


name = input('Enter Student Name : ')
fname = input('Enter Student Father Name : ')
class_name = input("Enter Student Class : ")
section = input("Enter Student Section : ")
sql = 'insert into student(name, fname, class, section, status) values
("'+name+'", "'+fname+'", "'+class_name+'" , \
"'+section+'" , "active");'
cursor.execute(sql)

#Closing the connection


conn.close()
print('\n\n\nPress any key to continue....')
wait = input('\n\n\nPress any key to continue....')

#----------------------------------------------------------------------------------

# 3. Defining the add_marks function


def add_marks():

# Establishing a connection to the database


conn = mysql.connector.connect(
host='localhost',
database='report_card',
user='root',
password='kalpit369'
)

# Creating a cursor object


cursor = conn.connect()
#Calling Clear function
clear()

print('Add New Marks Screen')

#Prompt User to Input the required Details


admno = input('Enter admission NO : ')
term = input('Enter TERM Name : ')
session = input('Enter session : ')
phy = input('Enter marks in Physics : ')
chem = input('Enter marks in Chemistry : ')
math = input('Enter marks in maths : ')
eng = input('Enter marks in English : ')
comp = input('Enter marks in Computer : ')

sql = 'insert into marks (admno, term, session, phy, chem, math, eng, comp)
values ("'+admno+'", "'+term+'", "'+session+'", \
"'+phy+'", "'+chem+'", "'+math+'", "'+eng+'", "'+comp+'");'
cursor.execute(sql)

#Closing the connection


conn.close()
print('\n\n\n New Marks added successfully')
wait = input('\n\n\nPress any key to continue... ')

#**********************************************************************************
**********************************************************

# 4. Defining the Modify_student function : update/change the entries in database

def modify_student():

# Establishing a connection to the database


conn = mysql.connector.connect(
host='localhost',
database='report_card',
user='root',
password='kalpit369'
)

# Creating a cursor object


cursor = conn.cursor()

#Calling Clear function


clear()

print('Modify Student Information')


print('-'*120)

admno = input('Enter admission No : ')


print('\n1. Name')
print('\n2. Father Name')
print('\n3. Class')
print('\n4. Section')

#Prompt user to make choice:


choice = int(input('Enter your choice : '))
if choice == 1:
field = 'name'
elif choice == 2:
field = 'fname'
elif choice == 3:
field = 'class'
elif choice == 4:
field = 'section'
value = input('Enter new value : ')
sql = 'update student set '+field+'="'+value+'" where admno="'+admno+'";'
cursor.execute(sql)

#Closing the connection


conn.close()
print('\n\n\n Student Record Updated....')
wait = input('\n\n\nPress any key to continue... ')

#**********************************************************************************

# 5. Defining the Modify_marks function : Update/change the marks of students in


the database

def modify_marks():

# Establishing a connection to the database


conn = mysql.connector.connect(
host='localhost',
database='report_card',
user='root',
password='kalpit369'
)

# Creating a cursor object


cursor = conn.cursor()

#Calling Clear function


clear()

print('Modify Marks - Screen')


print('-'*120)

#Prompt User to Input the required Details


admno = input('Enter admission No : ')
term = input('Enter Term : ')
session = input('Enter Session : ')
print('\n1. Physics')
print('\n2. Chemistry')
print('\n3. Mathematics')
print('\n4. English')
print('\n5. Computer ')
print('\n\n')

#Prompt User to make choice


choice = int(input('Enter your Choice : '))
field = ''
if choice == 1:
field = 'phy'
if choice == 2:
field= 'chem'
if choice == 3:
field = 'math'
if choice == 4:
field = 'eng'
if choice == 5:
field = 'comp'

value = input('Enter new value : ')


sql = 'UPDATE marks set '+field+' = '+value+' where admno = '+admno+' AND term
= "'+term+'" \
AND session = "'+session+'";'
cursor.execute(sql)

#Prompt User to make choice


conn.close()
print('\n\n\n Marks Updated Successfully!!!.....')
wait = input('\n\n\n Press any key to continue.......')

#**********************************************************************************
# 6. Defining the search_student function with parameter field :seach existing
student record in database

def search_student(field):

# Establishing a connection to the database


conn = mysql.connector.connect(
host='localhost',
database='report_card',
user='root',
password='kalpit369'
)

# Creating a cursor object


cursor = conn.cursor()
sql = 'select * from student where '
msg = 'Enter '+field + ' :'
value = input(msg)

if field == 'admno':
sql = sql + field + '=' +value+ ';'
else:
sql = sql + field + ' like "%' +value+ '%" or fname like "%' +value+ '%";'
cursor.execute(sql)
records = cursor.fetchall()

#Calling Clear function


clear()

print('SEARCH RESULT FOR '+field+' : '+value)


print('-'*120)

for record in records:


print(record)

#Prompt User to make choice


conn.close()
wait = input('\n\n\n Press any key to continue......')

#**********************************************************************************

# 7. Defining the search_marks function : Extract the marks from the records of the
def search_marks():

# Establishing a connection to the database


conn = mysql.connector.connect(
host='localhost',
database='report_card',
user='root',
password='kalpit369'
)

# Creating a cursor object


cursor = conn.cursor()
admno = input('Enter admission No: ')
session = input('Enter Session : ')
sql = ('Select * from marks where admno =' +admno+ ' and Session : ' +session)

#Calling Clear function


clear()

print('Search Result for Admission No. : ' +admno+ 'Session : ' '+session')
cursor.execute(sql)
records = cursor.fetchall()

#Calling Clear function


clear()
print('Search Result for Admission No :' +admno + 'Session : ' +session)
print('-'*120)

for record in records:


print(record)

#Prompt User to make choice


conn.close()
wait = input('\n\n\n Press any key to continue.....')

#**********************************************************************************

# 8. Defining search_menu function :


def search_menu():
while True:

#Calling Clear function


clear()

#Calling Clear function


print('S E A R C H M E N U')
print('-'*120)
print('\n1 Admission No.')
print('\n2 Name / Father Name')
print('\n3 Student Term Marks')
print('\n4 back to main')
print('\n\n')

#Prompt User to make choice


choice = int(input('Enter Your Choice : '))
field = ''
if choice == 1:
field = 'admno'
search_student(field)
if choice == 2:
field = 'name'
search_student(field)
if choice == 3:
search_marks()
if choice == 4:
break

#**********************************************************************************

# 9. Defining the report_single_term function


def report_single_term():
# Establishing a connection to the database
conn = mysql.connector.connect(
host='localhost',
database='report_card',
user='root',
password='kalpit369'
)

# Creating a cursor object


cursor = conn.cursor()

# Getting the student's details


admno = input("Enter admission number: ")
session = input("Enter session: ")
term = input("Enter term: ")
sql = 'select s.admno, name, fname, phy, math, clem, eng, comp from \
student s, marks m where s.admno = m.admno and s.admno = "'+admno +'" and \
m.session = "'+session+'" and m.term = "'+term+'";'
cursor.execute(sql, (admno, session, term))
record = cursor.fetchone()

# Printing the report card


print(school_name)
print(school_address)
print('Phone :', school_phone, 'Email :', school_email )
print("Report card for admission number: ", admno)
print("_" * 120)
print('Subject', 'Max_Marks', 'Min_Marks', 'Marks_Obtained')
print('Physics', '100', '33', record[3])
print('Chemistry', '100', '33', record[4])
print('Mathematics', '100', '33', record[5])
print('English', '100', '33', record[6])
print('Computer_Science', '100', '33', record[7])

print('_'*120)
total = record[3] + record[4]+ record[5]+ record[6]+ record[7]
percentage = total * 100 / 500
print('Total Marks : ', total, '% Marks : ', percentage )

#Closing the connection


conn.close()
wait = input('\n\n\n Press any key to continue.....')

#**********************************************************************************

# 10. Defining the report_whole_class function: To display the entire class record
def report_whole_class():

# Establishing a connection to the database


conn = mysql.connector.connect(
host='localhost',
database='report_card',
user='root',
password='kalpit369'
)

# Creating a cursor object


cursor = conn.cursor()
clas = input('Enter Class : ')
section = input('Enter Section : ')
session = input('Enter Session : ')
term = input('Enter term : ')
sql = 'select s.admno, name, fname, phy, math, chem, eng, comp from \
student s, marks m where s.admno = m.admno AND s.class = "'+clas+'" AND
m.session = "'+session+'" '
cursor.execute(sql)
records = cursor.fetchall()

#Calling Clear function


clear()

#Printing the School Details:


print(school_name)
print(school_address)
print('Phone No. : ', school_phone, 'Email : ' ,school_email)
print('-'*120)

print('Class Wise Report Card :', clas, '-', section, 'Session : ', session,
'Term : ', term)
print('-'*120)

t = PrettyTable(['admno', 'Name', 'Father Name', 'Phy', 'Chem', 'Math', 'Eng',


'Comp', 'Total'])
for idr, name, fname, phy, chem, math, eng, comp in records:
total = phy+chem+math+eng+comp
t.add_row(idr, name, fname, phy, chem, math, eng, comp, total)
print(t)

#Closing the connection


conn.close()
wait = input('\n\n\n Press any key to continue.....')

#**********************************************************************************

# 11. Definng the report_whole_session function: Display the record of entire


session
def report_whole_session():

# Establishing a connection to the database


conn = mysql.connector.connect(
host='localhost',
database='report_card',
user='root',
password='kalpit369'
)

# Creating a cursor object


cursor = conn.cursor()
session = input('Enter Session : ')
sql = 'select s.admno, name, fname, section, term, phy, math, chem, eng, comp
from \
student s, marks m where s.admn = m.admno and m.session = "'+session+'"
ORDER By class, section, term;'
cursor.execute(sql)
records = cursor.fetchall

#Calling Clear function


clear()

#Printing the School Details:


print(school_name)
print(school_address)
print('Phone No. : ', school_phone, 'Email : ' ,school_email, '\n\n')

print('Whole Session Report Card : ', ' Session : ', session)


print('-'*120)

t = PrettyTable(['admno','Name', 'Father Name','Class','Session', 'Term',


'Phy',
'Chem', 'Math', 'Eng', 'Comp', 'Total'])

for idr, name, fname, clas1, section, term, phy, chem, math, eng, comp in
records:
total = phy+chem+math+eng+comp
t.add_row([idr, name, fname, clas1, section, term, phy, chem, math, eng,
comp, total])
print(t)

#Closing the connection


conn.close()
wait = input('\n\n\n Press any key to continue........')

#**********************************************************************************

# 12. Defining report_topper_list function: Display the student records who secure
topmost postion
def report_topper_list():

# Establishing a connection to the database


conn = mysql.connector.connect(
host='localhost',
database='report_card',
user='root',
password='kalpit369'
)

# Creating a cursor object


cursor = conn.cursor()
session = input('Enter Session : ')
term = input('Enter Session : ')
clas = input('Enter Class : ')
section = input('Enter Section : ')
sql = 'select s.admno, name, fname, phy, chem, math, eng, comp,
phy+chem+math+comp "Total" \
from students s, marks m where s.admno = m.admno and class = "'+clas+'"
and section = "'+section+'" and \
session = "'+session+'" and term = "'+term+'" '
cursor.execute(sql)
records = cursor.fetchall

#Calling Clear function


clear()

#Printing the School Details:


print(school_name)
print(school_address)
print('Phone No. : ', school_phone, 'Email : ' ,school_email, '\n\n')

print('T O P P E R L I S T \n\n\n Class :', clas, '


Session : ' , \
session, ' Term : ', term)
print('-'*120)

t = PrettyTable(['admno' 'Name', '"Father Name', 'Physics', 'Chemistry',


'Mathematics', 'English', 'Computer', 'Total'])

for idr, name, fname, phy, chem, math, eng, comp, total in records:
t.add_row(idr, name, fname, phy, chem, math, eng, comp, total)
print(t)

#Closing the connection


conn.close()
wait = input('\n\n\n Press any key to continue............')

#**********************************************************************************

# 13. Defining report_menu function: Give access the user to display desired record
def report_menu():
while True:

#Calling Clear function


clear()
print(' R E P O R T M E N U')
print('\n1. Single Term Report Card')
print('\n2. Whole Class Report Card')
print('\n3. Whole Session Report Card')
print('\n4. Class Wise - Toppers')
print('\n\n')

#Prompt User to make a choice


choice = int(input('Enter your choice......: '))
if choice == 1:
report_single_term()
if choice == 2:
report_whole_class()
if choice == 3:
report_whole_session()
if choice == 4:
report_topper_list()
if choice == 5:
break

#**********************************************************************************

# 14. Defining the main_menu function : Prompt the user to access/update the
database.
def main_menu():
while True:

#Calling Clear function


clear()

#Printing the screen datails of the function so that user see which option
to choose
print(' R E P O R T C A R D M E N U ')
print("\n1. Add Student")
print("\n2. Modify Students")
print("\n3. Add Marks")
print("\n4. Modify Menu")
print("\n5. Search Menu")
print("\n6. Report Menu")
print('\n7. Close Application')
print('\n\n')

#Prompt User to make choice


choice = int(input('Enter Your Choice : '))
if choice == 1:
add_student()
if choice == 2:
modify_student()
if choice == 3:
add_marks()
if choice == 4:
modify_marks()
if choice == 5:
search_menu()
if choice == 6:
report_menu()
if choice == 7:
break

#**********************************************************************************

#Setting main_function in the loop:


if __name__ == "__main__":

#Calling the function:


main_menu()

Source Code In My SQL:


CREATE SCHEMA `report_card_backup` ;

CREATE TABLE `report_card_management`.`student` (


`admno` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(30) NULL,
`fname` VARCHAR(30) NULL,
`class` VARCHAR(15) NULL,
`section` VARCHAR(10) NULL,
`status` CHAR(15) NULL,
PRIMARY KEY (`admno`));

CREATE TABLE `report_card_management`.`marks` (


`admno` INT(11) NULL,
`term` VARCHAR(20) NULL,
`session` VARCHAR(20) NULL,
`phy` INT(3) NULL,
`chem` INT(3) NULL,
`math` INT(3) NULL,
`eng` INT(3) NULL,
`comp` INT(3) NULL);

ALTER TABLE `report_card`.`marks`


CHANGE COLUMN `admno` `admno` INT NOT NULL ,
ADD PRIMARY KEY (`admno`);
THANK
YOU VERY
MUCH!!

You might also like