0% found this document useful (0 votes)
15 views

Python_basic_1

This document outlines a Python-based Student Grade Management System that allows users to manage student records by adding, viewing, updating, and deleting student names and grades. It includes code for loading and saving student data in JSON format, as well as functions for each of the management tasks. The system features a menu-driven interface for user interaction.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Python_basic_1

This document outlines a Python-based Student Grade Management System that allows users to manage student records by adding, viewing, updating, and deleting student names and grades. It includes code for loading and saving student data in JSON format, as well as functions for each of the management tasks. The system features a menu-driven interface for user interaction.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Student Grade Management System

Your Name
March 24, 2025

1 Introduction
This document presents a Python-based Student Grade Management System.
Users can add, view, update, and delete student records, including their names
and grades.

2 Python Code
1 import json
2
3 STUDENT_FILE = " students . json "
4
5 def load_students () :
6 try :
7 with open ( STUDENT_FILE , " r " ) as file :
8 return json . load ( file )
9 except ( FileNotFoundError , json . JS O ND ec o de Er ro r ) :
10 return {}
11
12 def save_students ( students ) :
13 with open ( STUDENT_FILE , " w " ) as file :
14 json . dump ( students , file , indent =4)
15
16 def add_student ( students ) :
17 name = input ( " Enter student name : " ) . strip ()
18 try :
19 grade = float ( input ( " Enter student grade : " ) )
20 students [ name ] = grade
21 save_students ( students )
22 print ( f " Student ’{ name } ’ added with grade { grade }.\ n " )
23 except ValueError :
24 print ( " Invalid grade ! Please enter a number .\ n " )
25
26 def view_students ( students ) :
27 if not students :
28 print ( " \ n No student records available !\ n " )
29 else :
30 print ( " \ n Student Grades : " )
31 for name , grade in students . items () :
32 print ( f " { name }: { grade } " )

1
33 print ()
34
35 def update_s tudent ( students ) :
36 name = input ( " Enter student name to update : " ) . strip ()
37 if name in students :
38 try :
39 new_grade = float ( input ( f " Enter new grade for { name }: "
))
40 students [ name ] = new_grade
41 save_students ( students )
42 print ( f " Grade updated for ’{ name } ’ to { new_grade }.\
n")
43 except ValueError :
44 print ( " Invalid grade ! Please enter a number .\ n " )
45 else :
46 print ( " Student not found !\ n " )
47
48 def delete_s tudent ( students ) :
49 name = input ( " Enter student name to delete : " ) . strip ()
50 if name in students :
51 del students [ name ]
52 save_students ( students )
53 print ( f " Student ’{ name } ’ removed !\ n " )
54 else :
55 print ( " Student not found !\ n " )
56
57 def main () :
58 students = load_students ()
59
60 while True :
61 print ( " \ n Student Grade Management Menu : " )
62 print ( " 1 View Students " )
63 print ( " 2 Add Student " )
64 print ( " 3 Update Student Grade " )
65 print ( " 4 Delete Student " )
66 print ( " 5 Exit " )
67
68 choice = input ( " Choose an option (1 -5) : " ) . strip ()
69
70 if choice == " 1 " :
71 view_students ( students )
72 elif choice == " 2 " :
73 add_student ( students )
74 elif choice == " 3 " :
75 upda te_stude nt ( students )
76 elif choice == " 4 " :
77 dele te_stude nt ( students )
78 elif choice == " 5 " :
79 print ( " Exiting Student Management System . Have a
great day !\ n " )
80 break
81 else :
82 print ( " Invalid option ! Please try again .\ n " )
83
84 if __name__ == " __main__ " :
85 main ()

You might also like