Micro Project
on
[Student Management System]
Course Name: Scripting Language-Python
Course Code: 4330701
Semester: 3rd
Term: 241
Prepared By:
1. Muskan Sinha [236210307115]
Source Code:
Import os
# File to store student data
Filename = “students.txt”
# Add new student
Def add_student():
Roll = input(“Enter Roll Number: “)
Name = input(“Enter Name: “)
Marks = input(“Enter Marks: “)
With open(filename, “a”) as f:
f.write(f”{roll},{name},{marks}\n”)
print(“Student added successfully!\n”)
# View all students
Def view_students():
If not os.path.exists(filename):
Print(“No data found.\n”)
Return
Print(“\n--- Student Records ---“)
With open(filename, “r”) as f:
For line in f:
Roll, name, marks = line.strip().split(“,”)
Print(f”Roll No: {roll}, Name: {name}, Marks: {marks}”)
Print()
# Search student
Def search_student():
Roll_search = input(“Enter Roll Number to Search: “)
Found = False
With open(filename, “r”) as f:
For line in f:
Roll, name, marks = line.strip().split(“,”)
If roll == roll_search:
Print(f”Record Found: Roll No: {roll}, Name: {name}, Marks: {marks}\n”)
Found = True
Break
If not found:
Print(“Student not found.\n”)
# Update student
Def update_student():
Roll_update = input(“Enter Roll Number to Update: “)
Updated_lines = []
Found = False
With open(filename, “r”) as f:
For line in f:
Roll, name, marks = line.strip().split(“,”)
If roll == roll_update:
New_name = input(“Enter New Name: “)
New_marks = input(“Enter New Marks: “)
Updated_lines.append(f”{roll},{new_name},{new_marks}\n”)
Found = True
Print(“Student updated successfully.\n”)
Else:
Updated_lines.append(line)
With open(filename, “w”) as f:
f.writelines(updated_lines)
if not found:
print(“Student not found.\n”)
# Delete student
Def delete_student():
Roll_delete = input(“Enter Roll Number to Delete: “)
Updated_lines = []
Found = False
With open(filename, “r”) as f:
For line in f:
Roll, name, marks = line.strip().split(“,”)
If roll == roll_delete:
Found = True
Print(“Student deleted successfully.\n”)
Else:
Updated_lines.append(line)
With open(filename, “w”) as f:
f.writelines(updated_lines)
if not found:
print(“Student not found.\n”)
# Main menu
While True:
Print(“----- Student Management System -----“)
Print(“1. Add Student”)
Print(“2. View All Students”)
Print(“3. Search Student”)
Print(“4. Update Student”)
Print(“5. Delete Student”)
Print(“6. Exit”)
Choice = input(“Enter your choice (1-6): “)
If choice == “1”:
Add_student()
Elif choice == “2”:
View_students()
Elif choice == “3”:
Search_student()
Elif choice == “4”:
Update_student()
Elif choice == “5”:
Delete_student()
Elif choice == “6”:
Print(“Exiting…”)
Break
Else:
Print(“Invalid choice. Please try again.\n”)
Output: