Python Project (1)
Python Project (1)
School
Phalka Bazar, Lashkar, Gwalior, Madhya Pradesh -474001
1
Student Record Management Program - User
Manual
Introduction
Features
2
import pickle
filename = "students.dat"
# Initialize the file by taking user input
def write_initial_data():
students = [] # List to hold student
details
n = int(input("Enter the number of students
to add: "))
for _ in range(n):
roll = int(input("Enter Roll Number:
"))
name = input("Enter Name: ")
dob = input("Enter Date of Birth
(DD-MM-YYYY): ")
father_name = input("Enter Father's
Name: ")
stream = input("Enter Stream (e.g.,
Science, Commerce, Arts): ")
marks = float(input("Enter Marks (out
of 100): "))
students.append({"roll": roll, "name":
name, "dob": dob, "father_name": father_name,
"stream": stream, "marks": marks})
3
with open(filename, "wb") as file:
pickle.dump(students, file)
print("Data written to file successfully!")
4
# Add a new student
def add_student():
roll = int(input("Enter Roll Number: "))
name = input("Enter Name: ")
dob = input("Enter Date of Birth
(DD-MM-YYYY): ")
father_name = input("Enter Father's Name:
")
stream = input("Enter Stream (e.g.,
Science, Commerce, Arts): ")
marks = float(input("Enter Marks (out of
100): "))
students = load_data()
5
# View all student records
def view_students():
students = load_data()
if not students:
print("No records found!")
return
print("\nStudent Records:")
for student in students:
print("Roll:", student["roll"], ",
Name:", student["name"], ", DOB:",
student["dob"],
", Father's Name:",
student["father_name"], ", Stream:",
student["stream"], ", Marks:",
student["marks"])
6
# Search and update student details
def search_and_update():
roll = int(input("Enter Roll Number to
search: "))
students = load_data()
for student in students:
if student["roll"] == roll:
print("Found: Roll:",
student["roll"], ", Name:", student["name"], ",
DOB:", student["dob"],
", Father's Name:",
student["father_name"], ", Stream:",
student["stream"], ", Marks:",
student["marks"])
7
# Delete a student record
def delete_student():
roll = int(input("Enter Roll Number to
delete: "))
students = load_data()
if len(updated_students) == len(students):
print("Roll number not found!")
return
save_data(updated_students)
print("Student deleted successfully!")
8
# Menu-driven program
def menu():
while True:
print("\nStudent Record Management")
print("1. Write Initial Data to File")
print("2. Add New Student")
print("3. View All Students")
print("4. Search and Update Marks")
print("5. Delete Student Record")
print("6. Exit")
choice = int(input("Enter ur choice:"))
if choice == 1:
write_initial_data()
elif choice == 2:
add_student()
elif choice == 3:
view_students()
elif choice == 4:
search_and_update()
elif choice == 5:
delete_student()
elif choice == 6:
print("Exiting the program.")
break
else:
print("Invalid choice!")
# Run the program
menu()
9
O/p
10
3. Viewing data
5. Deleting record
* Viewing again
6. Exiting
11
THANK YOU
12