forked from Tonguesten36/pp2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.student.mark.py
117 lines (98 loc) · 3.78 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
import os
import re
#Function to input student information
def input_student(students: list) -> None:
temp = {} # create a temp dictionary to store student information
student_name = input("Enter student name: ")
while True: # check to see if student name is valid
if re.match(r"[a-zA-Z ]+", student_name): # using regex to check if student name is valid
break
else:
student_name = input("Student name is not valid, please try again: ")
student_id = input("Enter student id: ").upper() # convert to uppercase
while True:
# if student id is BIxx-xxx (x is digit)
if re.match(r"BI\d{2}-\d{3}", student_id):
break
else:
student_id = input("Student id is not valid, please try again: ")
DoB = input("Enter student DoB: ")
# if DoB is xx-xx-xxxx or xx/xx/xxxx
while True:
if re.match(r"\d{2}-\d{2}-\d{4}", DoB) or re.match(r"\d{2}/\d{2}/\d{4}", DoB):
break
else:
DoB = input("DoB is not valid, please try again: ")
temp["student_name"] = student_name
temp["student_id"] = student_id
temp["Date of birth"] = DoB
temp["course"] = []
students.append(temp)
#input course information
def input_course(courses: list) -> None:
temp = {}
course_name = input('Enter course name: ')
course_id = input('Enter course id: ')
temp["course_name"] = course_name
temp["course_id"] = course_id
courses.append(temp)
#input mark
def input_mark(students: list, courses: list) -> None:
student_id_input = input("Enter student id you want to input mark: ")
course_id_input = input("Enter course id to input mark: ")
mark = input("Enter mark: ")
course_name_searced = ""
for course in courses:# search for course name
if course["course_id"] == course_id_input:
course_name = course["course_name"]
break
for student in students:# search for student id
if student["student_id"] == student_id_input:
student["course"].append({"course_name": course_name, "mark": mark})
break
def main ():
students = []
courses = []
while True:
print("\033c") # clear screen
#print out all the options
print("1. Input student")
print("2. Input course")
print("3. Input mark")
print("4. Print student")
print("5. Print courses")
print("6. Exit")
choice = input("Enter your option: ")
while True:
try:
choice = int(choice)
if choice in range (1,7):
break
else:
raise ValueError
except ValueError:
choice = input("Input not valid , please try again: ")
match choice: # match the choice with the function
case 1:
input_student(students)
case 2:
input_course(courses)
case 3:
input_mark(students,courses)
case 4:
for student in students:
print("="*20)
print("Student name: " + student["student_name"])
print("Student id: " + student["student_id"])
print("Date of birth: " + student["Date of birth"])
for course in student["course"]:
# print("Course: " + course["course_name"] + ": " + course["mark"])
print(f"Course: {course['course_name']}: {course['mark']}")
case 5:
for course in courses:
print(course)
case 6:
break
input("Enter to continue...")
if __name__ == "__main__":
main()