0% found this document useful (0 votes)
398 views13 pages

Student Grading System in Python

The document describes a student grading system project created by Aditya Kumar for a computer science class, which involves connecting a Python script to a MySQL database to perform operations like inserting, updating, deleting, and searching student records as well as calculating grades based on marks in various subjects. The code allows the user to choose different operations to manage student data in the database and print query results.

Uploaded by

Vaibhav Pareta
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)
398 views13 pages

Student Grading System in Python

The document describes a student grading system project created by Aditya Kumar for a computer science class, which involves connecting a Python script to a MySQL database to perform operations like inserting, updating, deleting, and searching student records as well as calculating grades based on marks in various subjects. The code allows the user to choose different operations to manage student data in the database and print query results.

Uploaded by

Vaibhav Pareta
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

COMPUTER SCIENC PROJECT

STUDENT GRADING SYSTEM

Aditya Kumar
12 – F
Roll no: 3

TOPIC: Python Connectivity with MySQL


CERTIFICATE
This is to certify that the project titled
Student Grading System is prepared under
by guidance and supervision by Aditya
Kumar of class 12 – F in Computer Science
for the academic session 2020-2021

Submitted to Ms. Pallavi Sharma


Signature: __________
ACKNOWLEDGEMENT
I would like to express my special thanks of gratitude to my
computer science teacher “Ms. Pallavi Sharma” for her able
guidance and support in completing my project.

Then I would like to thank my parents and friends who have


helped me with their valuable suggestions and their guidance
has been helpful in various phases of the completion of the
project.
CODE:
import [Link] as database

connection=[Link](host="localhost", user='root',
passwd='1234', database='test')
cursor=[Link]()

def update_record():
roll=input("Which student's details do you want to
update?\nRoll No: ")
choice=int(input("[UPDATING DETAILS]\n\n1. Roll No\n2.
Name\n3. Class\nEnter Choice : "))
print()
if choice==1:
new_roll=int(input("Enter the new roll no: "))
update=f"update students set RollNo={new_roll} where
RollNo={roll}"
[Link](update)

[Link]("select * from students")


for i in cursor:
print(i)
elif choice == 2:
new_name=input("Enter the new name: ")
update=f'update students set Name="{new_name}"
where RollNo={roll}'

[Link](update)

[Link]("select * from students")


for i in cursor:
print(i)

elif choice==3:
new_class=int(input("Enter the new class: "))
update=f"update students set Class={new_class} where
RollNo={roll}"
[Link](update)

[Link]("select * from students")


for i in cursor:
print(i)
print()

def insert_record():
roll = int(input("Enter Roll No : "))
name = input("Enter Name : ")
class_int = int(input("Enter Class : "))
insert=f'insert into students
values({roll},"{name}",{class_int},"-","")'
print(insert)

[Link](insert)
[Link](f'select * from students where Name =
"{name}"')
print()
for i in cursor:
print(i);
print()

def delete_record():
roll=int(input("[DELETING]\n\nWhich entry would you like
to delete?\n Roll No: "))
delete=f"delete from students where RollNo={roll}"
[Link](delete)
[Link]("select * from students");
print()
for i in cursor:
print(i)
print()

def grade():

roll = int(input("Roll No. of student : "))


mathsMarks = int(input("Maths Marks (out of 100) : "))
physicsMarks = int(input("Physics Marks (out of 100) : "))
chemMarks = int(input("Chemistry Marks (out of 100) : "))
compMarks = int(input("CS Marks (out of 100) : "))
englishMarks = int(input("English Marks (out of 100) : "))

totalMarks =
mathsMarks+physicsMarks+chemMarks+compMarks+english
Marks
percent = round((totalMarks/500)*100,2)

if percent >= 95:


grade = "A+"
elif percent >= 85 and percent < 95:
grade = "A"
elif percent >= 75 and percent < 85:
grade = "B"
elif percent >= 55 and percent < 75:
grade = "C"
elif percent >= 35 and percent < 55:
grade = "D"
else:
grade = "F"

percentStr = str(percent)+" %"

update=f"update students set percentage='{percentStr}'


where RollNo={roll}"
[Link](update)
update2 = f"update students set grade='{grade}' where
RollNo={roll}"
[Link](update)
print(f"\nPercentage : {percentStr} with a grade of
{grade}")
print(f'\nUpdated record for student with roll no {roll}\n')
# MAIN
while True:
choice = int(input("\nWhat operation would you like to
perform?\n1. Insert a new record\n2. Delete a record\n3.
Update a record\n4. Search for record\n5. Display ALL\n6.
Grading\n7. Exit program\nEnter Choice --->"))
print("")
if choice==1:
insert_record()
elif choice==2:
delete_record()
elif choice==3:
update_record()

elif choice == 4:

d=int(input("Enter roll no:"))


s =f'select * from students where RollNo = {d}'
[Link](s)
print()
for i in cursor:
print(i)
print()
elif choice == 5:

[Link]("select * from students order by RollNo


asc")
print()
for i in cursor:
print(i)
print()
elif choice == 6:

grade()

elif choice == 7:

print("\nExiting the program...")


exit()

[Link]()
OUTPUT:

Common questions

Powered by AI

Managing database operations within a continuous loop ensures that the program remains responsive and can handle multiple transactions in succession. However, potential issues include increased memory usage and risk of unintentional infinite loops if exit conditions are not correctly managed. There is also a risk of database locks if operations take too long to execute. Efficient resource management techniques, such as committing transactions appropriately and handling exceptions, are necessary to prevent potential performance degradation .

The Python script provides options to update a student's roll number, name, or class by prompting the user to select from these options. Specifically, the script asks for the roll number of the student whose details need updating and then offers a menu for selecting the attribute to change: roll number, name, or class. Based on the user's choice, the script executes an SQL update command on the respective record in the database .

The Python script uses inline SQL strings with direct user input for constructing SQL statements, which makes it vulnerable to SQL injection attacks where malicious inputs could alter the SQL command behavior unexpectedly. A safer alternative is to use parameterized queries or prepared statements provided by database connectors like MySQL connector in Python, which separate SQL commands from data inputs to prevent execution of arbitrary SQL code by an attacker .

The student grading system project uses MySQL for managing student records which include insertion, deletion, update, and retrieval operations. This allows the program to interface with a database to store student information such as their roll numbers, names, class, grades, and calculated percentages. MySQL serves as the primary data storage and management system, supporting SQL operations to manipulate and query the data efficiently .

The project ensures data persistence across multiple program executions by storing all student records in a MySQL database. Changes made to the data, such as insertions, updates, and deletions, are committed to the database using the connection's commit method, ensuring that they are not lost between sessions and are available upon subsequent connections to the database .

The student's percentage is calculated by summing their marks in five subjects (maths, physics, chemistry, computer science, and English) and dividing by the total possible marks (500) to get a percentile score. The grade is assigned based on predefined percentage ranges: A+ (>= 95%), A (85-94%), B (75-84%), C (55-74%), D (35-54%), and F (<35%). These calculated values are then updated in the database using SQL update commands for the percentage and grade fields of the relevant student record using their roll number .

When a user selects the 'Display ALL' option, the program queries the MySQL database to retrieve all records from the 'students' table. It organizes the records by ordering them based on their roll numbers in ascending order using an SQL command, thereby providing a structured view of all student records in an ordered manner .

The 'cursor' object in the Python project serves as an intermediary for executing SQL commands over the database connection. It facilitates the execution of various SQL queries such as select, update, insert, and delete, and retrieves the results of these queries if applicable. The cursor also allows iteration over the result set for displaying output. It's an essential component for efficient database operations within the Python script .

The document does not explicitly mention error handling strategies for invalid user input or SQL exceptions. However, it could be inferred that the program would benefit from safer input validation techniques to prevent SQL injection and data type mismatches. Implementing try-except blocks for catching database connectivity issues or validation to check the existence of a record before updating or deleting would improve robustness .

Integrating Python with MySQL for managing student records combines Python's ease of use and flexibility with MySQL's robust data storage and management capabilities, allowing for efficient CRUD (Create, Read, Update, Delete) operations. This integration enables dynamic data handling, real-time updates, complex queries, and secure data manipulation within Python's scripting environment. As Python supports a broad range of libraries and frameworks, this synergy can be expanded with additional features like analytics or web interfacing .

You might also like