-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentManagementSystem.py
More file actions
134 lines (111 loc) · 4.49 KB
/
StudentManagementSystem.py
File metadata and controls
134 lines (111 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"""
Student Management System
==========================
1. Add Student
2. View Student -> All and One
3. Update Student
4. Delete Student
5. Exit
"""
class Student:
def __init__(self, name: str, age: int, address: str, marks: int) -> None:
self.name = name
self.age = age
self.address = address
self.marks = marks
class StudentManagementSystem:
def __init__(self):
self.students = []
def add_student(self):
while True:
name = input("Enter your name: ")
if name.replace(" ", "").isalpha():
break
else:
print("It's a invalid input. Enter only alphabets.")
age = int(input("Enter your age: "))
address = (input("Enter your address: "))
marks = int(input("Enter your marks: "))
student = Student(name, age, address, marks)
self.students.append(student)
print("Student Successfully Added..!")
return student
def view_students(self):
if len(self.students) == 0:
print("No Students found")
else:
view_type = input("All Students or One Student? (all/one): ")
if view_type == "all":
for student in self.students:
print(f"name: {student.name}\n age: {student.age}\n address: {student.address}\n marks: {student.marks}")
if view_type == "one":
name = input("Enter the name of the student you want to see: ")
for student in self.students:
if student.name == name:
print(f"name: {student.name}\n age: {student.age}\n address: {student.address}\n marks: {student.marks}")
def delete_student(self):
name = input("Enter the student you want to delete: ")
for student in self.students:
if student.name == name:
self.students.remove(student)
print("Student Successfully Deleted..!")
return self.students
def update_student(self):
name = input("Enter the student you want to update: ")
for student in self.students:
if student.name == name:
print(f"Student found: {student.name}\n Age: {student.age}\n Address: {student.address}\n Marks: {student.marks}")
print("What do you want to update?")
print("1. Name")
print("2. Age")
print("3. Address")
print("4. Marks")
print("5. Exit Update")
while True:
option = input("Enter your choice (1-5): ")
if option == "1":
new_name = input("Enter the new name: ")
if all(char.isalpha() or char.isspace() for char in new_name):
student.name = new_name
print("Name updated successfully!")
else:
print("Invalid name. Please use only alphabets and spaces.")
elif option == "2":
student.age = int(input("Enter the new age: "))
print("Age updated successfully!")
elif option == "3":
student.address = input("Enter the new address: ")
print("Address updated successfully!")
elif option == "4":
student.marks = int(input("Enter the new marks: "))
print("Marks updated successfully!")
elif option == "5":
print("Exiting update.")
break
else:
print("Invalid choice. Please enter a number between 1 and 5.")
print("Student Successfully Updated..!")
break
return student
print("Student not found")
print("Welcome to the Student Management System.")
system = StudentManagementSystem()
while True:
print("1. Add Student")
print("2. Delete Student")
print("3. Update Student")
print("4. View Student")
print("5. Exit the System")
choice = int(input("Enter your choice (1-5): "))
if choice == 1:
system.add_student()
elif choice == 2:
system.delete_student()
elif choice == 3:
system.update_student()
elif choice == 4:
system.view_students()
elif choice == 5:
break
else:
print("Invalid Choice")