Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Python Project

Class 12 python project

Uploaded by

cvt3zuuuyi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Python Project

Class 12 python project

Uploaded by

cvt3zuuuyi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Student Record Management Program - User

Manual
Introduction

The Student Record Management Program is a simple console-based


application that allows you to manage student records. The program allows
you to:

● Add new student records


● View all student records
● Search and update student marks
● Delete student records

The data is stored in a binary file (students.dat), and it uses Python's


pickle module for data serialization and deserialization.

Features

1. Write Initial Data: Add multiple student records to the file.


2. Add New Student: Add a single new student record to the file.
3. View All Students: View the details of all students stored in the file.
4. Search and Update Marks: Search for a student by their roll number
and update their marks.
5. Delete Student Record: Delete a student record by their roll number.

1
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})

2
with open(filename, "wb") as file:
pickle.dump(students, file)
print("Data written to file successfully!")

# Load data from the binary file


def load_data():
try:
with open(filename, "rb") as file:
return pickle.load(file)
except FileNotFoundError:
print("Error: The file does not exist.
Please write data first.")
return [] # Return an empty list if
the file is not found
except EOFError:
print("Error: The file is empty or has
no valid data.")
return []
# Save data back to the binary file
def save_data(students):
with open(filename, "wb") as file:
pickle.dump(students, file)

3
# 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()

# Check for duplicate roll number


for student in students:
if student["roll"] == roll:
print("Error: Roll number already
exists!")
return

students.append({"roll": roll, "name":


name, "dob": dob, "father_name": father_name,
"stream": stream, "marks": marks})
save_data(students)

4
print("Student added successfully!")

# 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"])

5
# 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"])

update_choice = input("Do you want


to update marks? (yes/no): ").lower()
if update_choice == "yes":
new_marks = float(input("Enter
new marks: "))
student["marks"] = new_marks
save_data(students)
print("Marks updated
successfully!")
return

6
print("Roll number not found!")

# Delete a student record


def delete_student():
roll = int(input("Enter Roll Number to
delete: "))
students = load_data()

updated_students = [] # This will store


the students to be kept
for student in students:
if student["roll"] != roll: # Only add
the students who do not match the roll number
updated_students.append(student)

if len(updated_students) == len(students):
print("Roll number not found!")
return

save_data(updated_students)
print("Student deleted successfully!")

7
# 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!")

8
# Run the program
menu()

O/p

1. Writing data to the file

2. Adding new Student

9
3. Viewing data

4. Searching and updating marks

5. Deleting record

* Viewing again

6. Exiting

10
THANK YOU

11

You might also like