STUDENT REGISTRATION SYSTEM (1)
STUDENT REGISTRATION SYSTEM (1)
Session : 2023-24
Signature of Principal
Acknowledgements
Thank You
Table of Contents Page no
1. Cover Page 1
2. Certificate 2
3. Acknowledgements 3
4. Table Of Contents 4
5. PROJECT INTRODUCTION 5
6. Objective of the Project 7
7. Source code 9
8. Output 14
9. Data used 17
PROJECT ON STUDENT
REGISTRATION SYSTEM
Students are the most important entity of an institution.
It is, therefore, important to maintain error-free records
of all students. However, sometimes it become difficult to
maintain perfect records of all the students in one go. In
order to achieve flawless management of students details
and to keep data in an organized manner, “Students
Registration System” methodology is adopted.
CODE
#Student Registration System
def main_menu():
ch = 'y'
while ch == 'y':
print("***********STUDENT REGISTRATION SYSTEM*************")
print("1: To show databases")
print("2: To create a table")
print("3: To show tables present in the database")
print("4: To display structure of the table")
print("5: To add a record in the table")
print("6: To update a record in the table")
print("7: To delete a record from the table")
print("8: To display all the records from the table")
print("9: To sort the data in descending order of total")
print("10: To quit")
choice = int(input("Enter your choice"))
if choice == 1:
show_database()
elif choice == 2:
create_table()
elif choice == 3:
showtables()
elif choice == 4:
display_struc()
elif choice == 5:
add_rec()
elif choice == 6:
update_rec()
elif choice == 7:
delete_rec()
elif choice == 8:
fetch_data()
elif choice == 9:
topper_list()
elif choice == 10:
print("Exiting")
break
else:
print("Wrong input")
ch = input("Do you want to continue")
def show_database():
import mysql.connector
try:
db = mysql.connector.connect(host = "localhost", user = "root", password = "")
cursor = db.cursor()
cursor.execute("show databases")
for x in cursor:
print(x)
except:
print("Error in connection")
def create_table():
import mysql.connector
try:
db = mysql.connector.connect(host = "localhost", user = "root", password =
"", database = "school")
cursor = db.cursor()
cursor.execute("create table student1(rollno int primary key,\ name
varchar(20), stream varchar(10), total\ int, grade varchar(3), Class int)")
print("Table created")
except:
print("Error in connection")
def showtables():
import mysql.connector
try:
db = mysql.connector.connect(host = "localhost", user = "root", password = "",
database = "school")
cursor = db.cursor()
cursor.execute("show tables")
for x in cursor:
print(x)
except:
print("Error in connection")
def display_struc():
import mysql.connector
try:
db = mysql.connector.connect(host = "localhost", user = "root", password = "",
database = "school")
cursor = db.cursor()
cursor.execute("desc student1")
for x in cursor:
print(x)
except:
print("Error in connection")
def add_rec():
import mysql.connector
try:
db = mysql.connector.connect(host = "localhost", user = "root", password = "",
database = "school")
cursor = db.cursor()
rno = int(input("Enter roll number"))
nm = input("Enter name")
st = input("Enter stream")
tot = int(input("Enter total"))
gr = input("Enter grade")
C = int(input ("Enter class"))
sql_query = "insert into student1 values(%s,%s,%s,%s,%s,%s)"
val = (rno,nm,st,tot,gr,C)
cursor.execute(sql_query,val)
db.commit()
print("Record added")
except:
db.rollback()
print("Error, Record not added")
def update_rec():
import mysql.connector
try:
db = mysql.connector.connect(host = "localhost", user = "root", password = "",
database = "school")
cursor = db.cursor()
rno = int(input("Enter rollno"))
tot = int(input("Enter total"))
sql_query = "Update student1 set total = %s where rollno = %s"
val = (tot,rno)
cursor.execute(sql_query,val)
print(cursor.rowcount, "record updated")
db.commit()
except:
db.rollback()
print("Record not updated")
def delete_rec():
import mysql.connector
try:
db = mysql.connector.connect(host = "localhost", user = "root", password = "",
database = "school")
cursor = db.cursor()
rno = int(input("Enter rollno"))
sql_query = "delete from student1 where rollno = %s"
cursor.execute(sql_query,(rno,))
print(cursor.rowcount, "record deleted")
db.commit()
except:
db.rollback()
print("Record not deleted")
def fetch_data():
import mysql.connector
try:
db = mysql.connector.connect(host = "localhost", user = "root", password = "",
database = "school")
cursor = db.cursor()
cursor.execute("SELECT * FROM student1")
records = cursor.fetchall()
for x in records:
print(x[0],x[1],x[2],x[3],x[4],x[5])
except:
print("Error, unable to fetch data")
def topper_list():
import mysql.connector
try:
db = mysql.connector.connect(host = "localhost", user = "root", password = "",
database = "school")
cursor = db.cursor()
cursor.execute("select * from student1 order by total desc")
records = cursor.fetchall()
for x in records:
print(x[0],x[1],x[2],x[3],x[4],x[5])
except:
print("Error, unable to sort")
main_menu()
once the above code is written and all modules are created,
upon execution, it will show the following output window:
In the above project, we have used formatting (%sign) with
print()statement, which we will discuss now.
FORMATTING DATA
SYMBOL DESCRIPTION
1) %c character
2) %s string
3) %d signed decimal
integer
4) %i integer
5) %u unsigned
decimal int
6) %o octal integer
7) %f floating
number
8) %e exponential
notation
9) %E exponential
notation
10)%x hexadecimal
lowercase
11)%X hexadecimal
uppercase