Students Result Maker Project
Students Result Maker Project
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
bash
Copy code
pip install mysql-connector-python
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;
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
cursor = db_connection.cursor()
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.")
if __name__ == "__main__":
main()
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:
mathematica
Copy code
Enter Student Name: Alice Brown
Enter Math Marks: 85
Enter Science Marks: 92
Enter English Marks: 88
Student Result Added Successfully!
markdown
Copy code
ID | Name | Math | Science | English | Total | Percentage | Grade
---------------------------------------------------------------------------
-----
1 | Alice Brown | 85 | 92 | 88 | 265 | 88.33 | B
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.