-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStuCourse.py
More file actions
320 lines (206 loc) · 7.8 KB
/
Copy pathStuCourse.py
File metadata and controls
320 lines (206 loc) · 7.8 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# 18 08 2026
students = []
all_courses = set()
# --------------------------------------------------
# 1. Add Student
# --------------------------------------------------
def add_student():
student_id = int(input("Enter Student ID:"))
student_name = input("Enter Student Name:")
# check if student already exist
for student in students:
if student["info"][0] == student_id:
print("Student ID already exist.")
return
# Tuple -> stores basic student information
student_info = (student_id, student_name)
# Dictionary -> stores all information of one student
student = {
"info" : student_info,
"courses" : set(),
"marks" : {}
}
students.append(student)
print("Student added successfully.")
# --------------------------------------------------
# 2. Add Courses
# --------------------------------------------------
def add_courses():
student_id = int(input("Enter Student ID: "))
for student in students:
if student["info"][0] == student_id:
number = int(input("How many courses do you want to add? "))
for i in range(number):
course = input("Enter course name: ")
# Set automatically prevents duplicates
student["courses"].add(course)
# Add course to overall course collection
all_courses.add(course)
print("Courses added successfully.")
return
print("Student not found.")
# --------------------------------------------------
# 3. Enter Marks
# --------------------------------------------------
def enter_marks():
student_id = int(input("Enter Student ID: "))
for student in students:
if student["info"][0] == student_id:
number = int(input("How many subjects do you want to enter marks for? "))
for i in range(number):
subject = input("Enter subject/course name: ")
marks = float(input("Enter marks: "))
student["marks"][subject] = marks
print("Marks added successfully.")
return
print("Student not found.")
# --------------------------------------------------
# 4. Display Student Details
# --------------------------------------------------
def display_student():
student_id = int(input("Enter Student ID: "))
for student in students:
if student["info"][0] == student_id:
print("\n----- STUDENT DETAILS -----")
print("Student ID:", student["info"][0])
print("Student Name:", student["info"][1])
print("Courses Enrolled:")
if len(student["courses"]) == 0:
print("No courses enrolled.")
else:
for course in student["courses"]:
print("-", course)
print("Marks:")
if len(student["marks"]) == 0:
print("No marks entered.")
else:
for subject, marks in student["marks"].items():
print(subject, ":", marks)
return
print("Student not found.")
# --------------------------------------------------
# 5. Display All Students
# --------------------------------------------------
def display_all_students():
if len(students) == 0:
print("No students available.")
return
print("\n========== ALL STUDENTS ==========")
for student in students:
print("\nStudent ID:", student["info"][0])
print("Student Name:", student["info"][1])
print("Courses:", student["courses"])
print("Marks:", student["marks"])
print("--------------------------------")
# --------------------------------------------------
# 6. Display All Courses
# --------------------------------------------------
def display_all_courses():
if len(all_courses) == 0:
print("No courses available.")
return
print("\n----- ALL UNIQUE COURSES -----")
for course in all_courses:
print(course)
print("Total Courses:", len(all_courses))
# --------------------------------------------------
# 7. Calculate Average Marks
# --------------------------------------------------
def calculate_average():
student_id = int(input("Enter Student ID: "))
for student in students:
if student["info"][0] == student_id:
marks = student["marks"]
if len(marks) == 0:
print("No marks available.")
return
total = sum(marks.values())
average = total / len(marks)
print("Student Name:", student["info"][1])
print("Average Marks:", average)
return
print("Student not found.")
# --------------------------------------------------
# 8. Find Students Enrolled in a Course
# --------------------------------------------------
def find_students_by_course():
search_course = input("Enter course name: ")
found = False
print("\nStudents enrolled in", search_course, ":")
for student in students:
if search_course in student["courses"]:
print(student["info"][1])
found = True
if found == False:
print("No students found for this course.")
# --------------------------------------------------
# 9. Remove a Course
# --------------------------------------------------
def remove_course():
student_id = int(input("Enter Student ID: "))
course = input("Enter course to remove: ")
for student in students:
if student["info"][0] == student_id:
if course in student["courses"]:
# Remove course from student's set
student["courses"].remove(course)
# Remove corresponding marks if present
if course in student["marks"]:
del student["marks"][course]
print("Course removed from student.")
# Check whether any other student has this course
course_still_used = False
for other_student in students:
if course in other_student["courses"]:
course_still_used = True
break
# Remove from overall course set only if nobody uses it
if course_still_used == False:
all_courses.remove(course)
print("Course removed from overall course collection.")
return
else:
print("Student is not enrolled in this course.")
return
print("Student not found.")
# --------------------------------------------------
# Main Menu
# --------------------------------------------------
while True:
print("\n======================================")
print(" STUDENT COURSE MANAGEMENT SYSTEM")
print("======================================")
print("1. Add Student")
print("2. Add Courses")
print("3. Enter Marks")
print("4. Display Student Details")
print("5. Display All Students")
print("6. Display All Courses")
print("7. Calculate Average Marks")
print("8. Find Students Enrolled in a Course")
print("9. Remove a Course")
print("10. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
add_student()
elif choice == 2:
add_courses()
elif choice == 3:
enter_marks()
elif choice == 4:
display_student()
elif choice == 5:
display_all_students()
elif choice == 6:
display_all_courses()
elif choice == 7:
calculate_average()
elif choice == 8:
find_students_by_course()
elif choice == 9:
remove_course()
elif choice == 10:
print("Program terminated.")
break
else:
print("Invalid choice. Please try again.")