-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy path1.student.mark.py
264 lines (241 loc) · 7.68 KB
/
1.student.mark.py
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
# arrays containing info
students_id_list = []
students_info_list = []
courses_list = []
courses_id_list = []
marks = []
def NumOfStds():
while True:
num_of_students = int(input("Total number of students: "))
if (num_of_students < 0):
print("Negative number of students is not valid!")
else:
break
return num_of_students
# dictionary for student info
def CreateStudentDict(student_id, name, dob):
aboutStudent = {
"id": student_id,
"name": name,
"dob": dob
}
students_info_list.append(aboutStudent)
students_id_list.append(student_id)
def NumOfCourses():
while True:
num_of_courses = int(input("Total number of courses: "))
if num_of_courses < 0:
print("Negative number of courses is not valid")
else:
break
return num_of_courses
# create a dictionary for course info
def CreateCourseDict(course_id, name):
aboutCourse = {
"id": course_id,
"name": name
}
courses_list.append(aboutCourse)
courses_id_list.append(course_id)
# create a dictionary for marks
def CreateMarkDict(student_id, course_id, value):
aboutMark = {
"sid": student_id,
"cid": course_id,
"value": value
}
marks.append(aboutMark)
def StudentInfoQuery():
while True:
sid = input("Enter student ID: ")
if len(sid) == 0 or sid is None:
print("Negative student ID is not allowed!")
else:
break
if sid in students_id_list:
print("Student ID already exists")
exit()
else:
while True:
name = input("Enter student name: ")
if len(name) == 0 or name is None:
print("Student name cannot be empty!")
else:
break
while True:
dob = input("Enter student date of birth: ")
if len(dob) == 0 or dob is None:
print("Student date of birth cannot be empty!")
else:
break
print(f"Student {name} successfully added!")
CreateStudentDict(sid, name, dob)
def GetCourseInfo():
while True:
cid = input("Enter course ID: ")
if len(cid) == 0 or cid is None:
print("Course ID cannot be empty!")
else:
break
if cid in courses_id_list:
print("Course ID already exists!")
exit()
else:
while True:
name = input("Enter course name: ")
if len(name) == 0 or name is None:
print("Course name cannot be empty")
else:
break
print(f"Successfully added course: {name}")
CreateCourseDict(cid, name)
def GetCourseMarks(cid):
for s in students_info_list:
sid = s['id']
while True:
value = float(input(f"Enter marks for {s['name']}: "))
if value < 0:
print("Marks must be non-negative")
else:
break
CreateMarkDict(sid, cid, value)
def GetMarks():
while True:
cid = input("Enter Course ID for which you want to input marks: ")
if cid in courses_id_list:
if len(marks) > 0:
marked = False
for m in marks:
if m['cid'] == cid:
print("You have already input marks for this course")
marked = True
break
if not marked:
GetCourseMarks(cid)
else:
GetCourseMarks(cid)
break
elif len(cid) == 0 or cid is None:
print("Course ID cannot be empty!")
else:
print("No course found for the input ID")
return -1
def PrintCourses():
print("List of all Courses:")
for c in courses_list:
print("%s %s" % (c['id'], c['name']))
print()
def PrintStudents():
print("All Students in class:")
for s in students_info_list:
print("%s %s %s" % (s['id'], s['name'], s['dob']))
print()
def PrintCourseMarks(cid):
for m in marks:
if m['cid'] == cid:
sid = m['sid']
for s in students_info_list:
if s['id'] == sid:
print("%s %s %s" % (s['id'], s['name'], m['value']))
# Ask the user for the course ID whose mark should be listed, then invoke the PrintCourseMarks() function
def PrintMarks():
while True:
cid = input("Enter the course ID for which you want to see marks: ")
if len(cid) == 0 or cid is None:
print("Course ID cannot be empty!")
else:
break
if cid in courses_id_list:
PrintCourseMarks(cid)
else:
print("No course exists for the input ID")
return -1
def main():
print("1 = Input students' details")
print("2 = Input courses' details")
print("3 = Exit")
print()
myChoice = int(input("Enter your choice: "))
while True:
if myChoice == 1:
num_of_stds = NumOfStds()
for i in range(num_of_stds):
print(f"-Student {i + 1}-")
StudentInfoQuery()
while len(courses_list) == 0:
print("1 = Input courses' details")
print("2 = Exit")
myChoice2 = int(input("Enter your choice: "))
if myChoice2 == 1:
num_of_courses = NumOfCourses()
for i in range(num_of_courses):
print(f"Course {i + 1}:")
GetCourseInfo()
break
elif myChoice2 == 2:
exit()
else:
print("Invalid choice!")
break
elif myChoice == 2:
num_of_courses = NumOfCourses()
for i in range(num_of_courses):
print(f"Course {i + 1}:")
GetCourseInfo()
while len(students_info_list) == 0:
print("1 = Input students' details: ")
print("2 = Exit")
myChoice2 = int(input("Enter your choice: "))
if myChoice2 == 1:
num_of_stds = NumOfStds()
for i in range(num_of_stds):
print(f"Student {i + 1}:")
StudentInfoQuery()
break
elif myChoice2 == 2:
exit()
else:
print("Invalid choice!")
break
break
elif myChoice == 3:
exit()
else:
print("Invalid choice!")
exit()
while len(marks) < len(students_info_list) * len(courses_list):
print("1 = Input mark for a course")
print("2 = Print students")
print("3 = Print courses")
print("4 = Exit")
print()
myChoice3 = int(input("Enter your choice: "))
if myChoice3 == 1:
GetMarks()
elif myChoice3 == 2:
PrintStudents()
elif myChoice3 == 3:
PrintCourses()
elif myChoice3 == 4:
exit()
else:
print("Invalid choice!")
while True:
print("1 = Print students")
print("2 = Print courses")
print("3 = Print marks of a course")
print("4 = Exit")
myChoice3 = int(input("Your choice: "))
if myChoice3 == 1:
PrintStudents()
elif myChoice3 == 2:
PrintCourses()
elif myChoice3 == 3:
PrintMarks()
elif myChoice3 == 4:
print("Exit")
exit()
else:
print("Invalid choice!")
# invoke main function
main()