Day 3 · Day 3: Data Structures
Student Management System
Build a console-based Student Management System using Python lists and dictionaries. The program should let users add students, view all students, search for a student by name, update a student's grade, and remove a student from the system.
Requirements
1. Store students as dictionaries with keys: name, age, grade.
2. Keep all students in a list.
3. Implement a menu-driven loop with options: Add, View All, Search, Update Grade, Remove, Exit.
4. Searching should be case-insensitive.
5. Display a friendly message if a student is not found.
6. Print a numbered list when viewing all students.
2. Keep all students in a list.
3. Implement a menu-driven loop with options: Add, View All, Search, Update Grade, Remove, Exit.
4. Searching should be case-insensitive.
5. Display a friendly message if a student is not found.
6. Print a numbered list when viewing all students.
students = []
def add_student(name, age, grade):
students.append({"name": name, "age": age, "grade": grade})
print(f"Added student: {name}")
def view_students():
if not students:
print("No students found.")
return
for i, s in enumerate(students, start=1):
print(f"{i}. {s['name']} | Age: {s['age']} | Grade: {s['grade']}")
def search_student(name):
for s in students:
if s["name"].lower() == name.lower():
return s
return None
def update_grade(name, new_grade):
student = search_student(name)
if student:
student["grade"] = new_grade
print(f"Updated {name}'s grade to {new_grade}")
else:
print(f"Student '{name}' not found.")
def remove_student(name):
student = search_student(name)
if student:
students.remove(student)
print(f"Removed student: {name}")
else:
print(f"Student '{name}' not found.")
def main():
while True:
print("\n--- Student Management System ---")
print("1. Add Student")
print("2. View All Students")
print("3. Search Student")
print("4. Update Grade")
print("5. Remove Student")
print("6. Exit")
choice = input("Choose an option: ")
if choice == "1":
name = input("Name: ")
age = int(input("Age: "))
grade = input("Grade: ")
add_student(name, age, grade)
elif choice == "2":
view_students()
elif choice == "3":
name = input("Enter name to search: ")
result = search_student(name)
print(result if result else "Student not found.")
elif choice == "4":
name = input("Name: ")
new_grade = input("New grade: ")
update_grade(name, new_grade)
elif choice == "5":
name = input("Name: ")
remove_student(name)
elif choice == "6":
print("Goodbye!")
break
else:
print("Invalid option, try again.")
if __name__ == "__main__":
main()
50 XP on completion
Back to Day 3
Your Code
Output
Click "Run" to execute your code...
⏳ Loading Python runtime (first run may take a few seconds)...
Log in to mark this project complete and earn XP.