0% found this document useful (0 votes)
27 views3 pages

Student Registration System

Uploaded by

shruti chauhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

Student Registration System

Uploaded by

shruti chauhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Student Registration System Program

========================================

# Student Registration System

class Student:
def __init__(self, roll_no, name, age, gender, stream):
self.roll_no = roll_no
self.name = name
self.age = age
self.gender = gender
self.stream = stream

def __str__(self):
return f"Roll No: {self.roll_no}, Name: {self.name}, Age: {self.age},
Gender: {self.gender}, Stream: {self.stream}"

class StudentRegistrationSystem:
def __init__(self):
self.students = {}

def add_student(self, roll_no, name, age, gender, stream):


if roll_no in self.students:
print(f"Student with Roll No {roll_no} already exists.")
else:
student = Student(roll_no, name, age, gender, stream)
self.students[roll_no] = student
print(f"Student {name} added successfully!")

def view_student(self, roll_no):


if roll_no in self.students:
print(self.students[roll_no])
else:
print(f"No student found with Roll No {roll_no}.")

def update_student(self, roll_no, name=None, age=None, gender=None,


stream=None):
if roll_no in self.students:
student = self.students[roll_no]
if name:
student.name = name
if age:
student.age = age
if gender:
student.gender = gender
if stream:
student.stream = stream
print(f"Student {roll_no} updated successfully!")
else:
print(f"No student found with Roll No {roll_no}.")

def delete_student(self, roll_no):


if roll_no in self.students:
del self.students[roll_no]
print(f"Student with Roll No {roll_no} deleted successfully!")
else:
print(f"No student found with Roll No {roll_no}.")
def display_all_students(self):
if self.students:
print("All Registered Students:")
for student in self.students.values():
print(student)
else:
print("No students registered yet.")

# Menu-driven program
def main():
system = StudentRegistrationSystem()

while True:
print("\n===== Student Registration System =====")
print("1. Add Student")
print("2. View Student")
print("3. Update Student")
print("4. Delete Student")
print("5. Display All Students")
print("6. Exit")
print("=======================================")

choice = input("Enter your choice (1-6): ")

if choice == '1':
roll_no = input("Enter Roll No: ")
name = input("Enter Name: ")
age = input("Enter Age: ")
gender = input("Enter Gender: ")
stream = input("Enter Stream (Science/Commerce/Arts): ")
system.add_student(roll_no, name, age, gender, stream)
elif choice == '2':
roll_no = input("Enter Roll No to View: ")
system.view_student(roll_no)
elif choice == '3':
roll_no = input("Enter Roll No to Update: ")
print("Leave fields empty if no change is needed.")
name = input("Enter Name (or leave blank): ")
age = input("Enter Age (or leave blank): ")
gender = input("Enter Gender (or leave blank): ")
stream = input("Enter Stream (or leave blank): ")
system.update_student(roll_no, name=name, age=age, gender=gender,
stream=stream)
elif choice == '4':
roll_no = input("Enter Roll No to Delete: ")
system.delete_student(roll_no)
elif choice == '5':
system.display_all_students()
elif choice == '6':
print("Exiting the program.")
break
else:
print("Invalid choice! Please choose again.")

if __name__ == "__main__":
main()
========================================
Sample Output
========================================

===== Student Registration System =====


1. Add Student
2. View Student
3. Update Student
4. Delete Student
5. Display All Students
6. Exit
=======================================
Enter your choice (1-6): 1
Enter Roll No: 101
Enter Name: John Doe
Enter Age: 17
Enter Gender: Male
Enter Stream (Science/Commerce/Arts): Science
Student John Doe added successfully!

===== Student Registration System =====


1. Add Student
2. View Student
3. Update Student
4. Delete Student
5. Display All Students
6. Exit
=======================================
Enter your choice (1-6): 5
All Registered Students:
Roll No: 101, Name: John Doe, Age: 17, Gender: Male, Stream: Science

You might also like