└── Student management /Student management: -------------------------------------------------------------------------------- 1 | # Initialize an empty dictionary to store student data 2 | students = {} 3 | 4 | # Function to add a new student 5 | def add_student(student_id, name, age, major): 6 | students[student_id] = { 7 | 'name': name, 8 | 'age': age, 9 | 'major': major 10 | } 11 | 12 | # Function to remove a student 13 | def remove_student(student_id): 14 | if student_id in students: 15 | del students[student_id] 16 | else: 17 | print(f"Student ID {student_id} not found.") 18 | 19 | # Function to get a student's information 20 | def get_student(student_id): 21 | return students.get(student_id, f"Student ID {student_id} not found.") 22 | 23 | # Function to list all students 24 | def list_students(): 25 | if students: 26 | for student_id, info in students.items(): 27 | print(f"ID: {student_id}, Name: {info['name']}, Age: {info['age']}, Major: {info['major']}") 28 | else: 29 | print("No students available.") 30 | 31 | # Adding some students 32 | add_student(1, 'Alice', 20, 'Computer Science') 33 | add_student(2, 'Bob', 21, 'Mathematics') 34 | add_student(3, 'Charlie', 22, 'Physics') 35 | 36 | # Removing a student 37 | remove_student(2) 38 | 39 | # Getting a student's information 40 | print(get_student(1)) 41 | 42 | # Listing all students 43 | list_students() 44 | --------------------------------------------------------------------------------