Text: Don't use ChatGPT to solve!!!
# Each entry corresponds to a lecture's timetable in this semester.
# Structure of timetable:
# timetable_ID: [course_ID, teacher_ID, start_time, end_time, venue_ID]
timetable_DB = {
1: [2, 100, "1230", "1320", 6],
2: [1, 101, "1330", "1520", 58],
3: [4, 101, "0930", "1220", 12],
}
# Each entry corresponds to the information of a course.
# Structure of course:
# course_ID: [code, name, faculty, department, curriculum]
course_DB = {
1: ["ENGG1000", "Intro to Engineering A", "Faculty of Engineering", "NA", "UG"],
2: ["ENGG1001", "Intro to Engineering B", "Faculty of Engineering", "NA", "UG"],
3: ["ELEC7001", "Machine Learning", "Faculty of Engineering", "Dept. EEE", "PG"],
4: ["MATH1001", "Intro to Calculus", "Faculty of Science", "Dept. Math", "UG"],
}
# Each entry corresponds to the information of a teacher.
# Structure of teacher:
# teacher_ID: [name, start_date]
teacher_DB = {
100: ["John", "2020-01-01"],
101: ["Mary", "2020-06-01"],
102: ["Peter", "2020-10-01"],
}
# Each entry corresponds to the information of a venue.
# Structure of venue:
# venue_ID: [name, capacity]
venue_DB = {
6: ["CBA", 60],
7: ["CBC", 90],
12: ["RHT", 200],
58: ["MWT1", 120],
}
def query_timetable(timetable_ID):
"""Return a dictionary containing data related to this timetable_ID. If this key does not exist in the
timetable dictionary, returns an empty dictionary.
Arguments:
timetable_ID: integer, key to the timetable_DB
Return:
A dictionary with keys "course_code", "course_name", "start_time", "end_time", "teacher_name", "venue_name".
If the key does not exist, return an empty dictionary {}
For example, if timetable_ID = 2, returns {
"course_code": "ENGG1000",
"course_name": "Intro to Engineering A",
"start_time": "1330",
"end_time": "1520",
"teacher_name": "Mary",
"venue_name": "MWT1",
}
"""
global timetable_DB, course_DB, teacher_DB, venue_DB
# Write your code here
def change_course_name(course_ID, new_name):
"""Change the course name corresponding to course_ID to new_name. Assume the key exists.
Arguments:
course_ID: integer, key to the course_DB
new_name: str, the name used to replace the existing name
"""
global timetable_DB, course_DB, teacher_DB, venue_DB
# Write your code here
def change_teacher_name(teacher_ID, new_name):
"""Change the teacher name corresponding to teacher_ID to new_name. Assume the key exists.
Arguments:
teacher_ID: integer, key to the teacher_DB
new_name: str, the name used to replace the existing name
"""
global timetable_DB, course_DB, teacher_DB, venue_DB
# Write your code here
def change_timetable_venue(timetable_ID, new_venue_ID):
"""Change the venue_ID corresponding to timetable_ID to new_venue_ID. Assume the key exists.
Arguments:
timetable_ID: integer, key to the timetable_DB
new_venue_ID: integer, the venue ID used to replace the existing ID
"""
global timetable_DB, course_DB, teacher_DB, venue_DB
# Write your code here
def print_query_result(result):
if len(result) == 0:
print("timetable_ID does not exist")
else:
print(
f"{result['course_code']} '{result['course_name']}' is taught by {result['teacher_name']}"
+ f" and starts from {result['start_time']} to {result['end_time']}"
+ f" at {result['venue_name']}"
)
command = [""]
while command[0] != "end":
command = input().split(",")
if command[0] == "query":
result = query_timetable(int(command[1]))
print_query_result(result)
elif command[0] == "change_course_name":
change_course_name(int(command[1]), command[2])
elif command[0] == "change_teacher_name":
change_teacher_name(int(command[1]), command[2])
elif command[0] == "change_timetable_venue":
change_timetable_venue(int(command[1]), int(command[2]))