0% found this document useful (0 votes)
34 views4 pages

Students Result Maker Project

students result maker project

Uploaded by

roydeadmanx
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)
34 views4 pages

Students Result Maker Project

students result maker project

Uploaded by

roydeadmanx
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/ 4

Here’s an enhanced Student Result Maker project that includes Python code with MySQL

connectivity and CSV file handling. This program allows you to add student details, calculate
results based on marks, view results, and export data to a CSV file. Additionally, I’ll provide
expected sample output for each functionality.

Prerequisites

1. MySQL Database Setup:


o Install MySQL and create a database named student_results.
o Create a table in the database to store student marks and their calculated
results.
2. Python Libraries:
o Install the MySQL connector for Python:

bash
Copy code
pip install mysql-connector-python

MySQL Table Setup

Use the following SQL commands in MySQL to set up the database and table for this project.

sql
Copy code
CREATE DATABASE student_results;

USE student_results;

CREATE TABLE results (


student_id INT PRIMARY KEY AUTO_INCREMENT,
student_name VARCHAR(100),
math_marks INT,
science_marks INT,
english_marks INT,
total_marks INT,
percentage FLOAT,
grade CHAR(1)
);

Python Code for Student Result Maker

This Python script has options for adding student results, viewing all results, and exporting
results to a CSV file.

python
Copy code
import mysql.connector
import csv

# Connect to MySQL database


db_connection = mysql.connector.connect(
host="localhost",
user="root", # Replace with your MySQL username
password="password", # Replace with your MySQL password
database="student_results"
)

cursor = db_connection.cursor()

# Function to calculate total marks, percentage, and grade


def calculate_result(math_marks, science_marks, english_marks):
total_marks = math_marks + science_marks + english_marks
percentage = (total_marks / 300) * 100
if percentage >= 90:
grade = 'A'
elif percentage >= 75:
grade = 'B'
elif percentage >= 50:
grade = 'C'
elif percentage >= 35:
grade = 'D'
else:
grade = 'F'
return total_marks, percentage, grade

# Function to add a new student result


def add_student():
student_name = input("Enter Student Name: ")
math_marks = int(input("Enter Math Marks: "))
science_marks = int(input("Enter Science Marks: "))
english_marks = int(input("Enter English Marks: "))

# Calculate the result


total_marks, percentage, grade = calculate_result(math_marks,
science_marks, english_marks)

# Insert result into MySQL database


query = "INSERT INTO results (student_name, math_marks, science_marks,
english_marks, total_marks, percentage, grade) VALUES (%s, %s, %s, %s, %s,
%s, %s)"
data = (student_name, math_marks, science_marks, english_marks,
total_marks, percentage, grade)
cursor.execute(query, data)
db_connection.commit()
print("Student Result Added Successfully!")

# Function to view all results


def view_results():
cursor.execute("SELECT * FROM results")
results = cursor.fetchall()
print("ID | Name | Math | Science | English | Total |
Percentage | Grade")
print("-" * 80)
for row in results:
print(f"{row[0]:<3}| {row[1]:<12} | {row[2]:<4} | {row[3]:<7} |
{row[4]:<7} | {row[5]:<5} | {row[6]:<10.2f} | {row[7]}")

# Function to export results to CSV file


def export_results_to_csv():
cursor.execute("SELECT * FROM results")
results = cursor.fetchall()

with open("student_results.csv", mode="w", newline="") as file:


writer = csv.writer(file)
writer.writerow(["Student ID", "Student Name", "Math Marks",
"Science Marks", "English Marks", "Total Marks", "Percentage", "Grade"])
for row in results:
writer.writerow(row)
print("Results exported to student_results.csv successfully.")

# Main function to run the application


def main():
while True:
print("\n--- Student Result Maker ---")
print("1. Add Student Result")
print("2. View All Results")
print("3. Export Results to CSV")
print("4. Exit")
choice = input("Enter your choice: ")

if choice == '1':
add_student()
elif choice == '2':
view_results()
elif choice == '3':
export_results_to_csv()
elif choice == '4':
break
else:
print("Invalid choice. Please try again.")

# Close database connection


cursor.close()
db_connection.close()

if __name__ == "__main__":
main()

Explanation of Key Functions

1. calculate_result():
o Computes total_marks, percentage, and assigns a grade based on the
percentage.
2. add_student():
o Prompts the user for student details and marks.
o Uses calculate_result() to compute total, percentage, and grade.
o Inserts the calculated result into the results table in MySQL.
3. view_results():
o Fetches and displays all records from the results table.
4. export_results_to_csv():
o Exports all records from MySQL into a CSV file student_results.csv.
5. main():
o Provides a command-line menu to access program functions.
o Closes the database connection on exit.

Sample Output

Main Menu

sql
Copy code
--- Student Result Maker ---
1. Add Student Result
2. View All Results
3. Export Results to CSV
4. Exit
Enter your choice:

Adding a Student Result

mathematica
Copy code
Enter Student Name: Alice Brown
Enter Math Marks: 85
Enter Science Marks: 92
Enter English Marks: 88
Student Result Added Successfully!

Viewing All Results

markdown
Copy code
ID | Name | Math | Science | English | Total | Percentage | Grade
---------------------------------------------------------------------------
-----
1 | Alice Brown | 85 | 92 | 88 | 265 | 88.33 | B

Exporting Results to CSV

After choosing option 3, the program exports results to a CSV file named
student_results.csv with the following structure:

css
Copy code
Student ID,Student Name,Math Marks,Science Marks,English Marks,Total
Marks,Percentage,Grade
1,Alice Brown,85,92,88,265,88.33,B

Notes

 Database Connection: Ensure user, password, and host match your MySQL
configuration.
 Error Handling: Consider adding validation for mark inputs and handling for
database connection errors.
 CSV File: The CSV file allows for easy sharing and backup of student data.

This Student Result Maker project is designed to be simple, functional, and easy to extend
with additional features if needed.

You might also like