0% found this document useful (0 votes)
6 views

Adbmsminpcode

Uploaded by

aanusha22ecs
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)
6 views

Adbmsminpcode

Uploaded by

aanusha22ecs
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/ 2

# Initialize an empty list to act as our "database"

students = []

# Function to add a student


def add_student(name, age, department):
student_id = len(students) + 1 # Generate a simple incremental ID
student = {
"id": student_id,
"name": name,
"age": age,
"department": department
}
students.append(student)
print(f"Student {name} added successfully with ID: {student_id}")

# Function to view all students


def view_students():
if students:
for student in students:
print(f"ID: {student['id']}, Name: {student['name']}, Age:
{student['age']}, Department: {student['department']}")
else:
print("No students found.")

# Function to update a student


def update_student(student_id, name=None, age=None, department=None):
for student in students:
if student["id"] == student_id:
if name:
student["name"] = name
if age:
student["age"] = age
if department:
student["department"] = department
print(f"Student with ID {student_id} updated successfully!")
return
print(f"Student with ID {student_id} not found.")

# Function to delete a student


def delete_student(student_id):
global students
students = [student for student in students if student["id"] != student_id]
print(f"Student with ID {student_id} deleted successfully!")

# Main menu
def main():
while True:
print("\nStudent Management System")
print("1. Add Student")
print("2. View Students")
print("3. Update Student")
print("4. Delete Student")
print("5. Exit")

choice = input("Enter your choice: ")

if choice == '1':
name = input("Enter student's name: ")
age = int(input("Enter student's age: "))
department = input("Enter student's department: ")
add_student(name, age, department)

elif choice == '2':


view_students()

elif choice == '3':


student_id = int(input("Enter student ID to update: "))
name = input("Enter new name (or press Enter to skip): ")
age = input("Enter new age (or press Enter to skip): ")
department = input("Enter new department (or press Enter to skip): ")
update_student(student_id, name or None, int(age) if age else None,
department or None)

elif choice == '4':


student_id = int(input("Enter student ID to delete: "))
delete_student(student_id)

elif choice == '5':


print("Exiting...")
break

else:
print("Invalid choice, please try again.")

if __name__ == "__main__":
main()

You might also like