def test_remove_student_from_classroom(): """ Dependencies: - create_classroom() - add_student_to_classroom() """ student_Info = { "John Smith": markbook.create_student(first_name="John", last_name="Smith", gender="Male", image="jsmith.png", student_number=111, grade=9, email="*****@*****.**") } classroom_Info = { "ICS4U": markbook.create_classroom(course_code="ICS4U", course_name="Computer Science", period=2, teacher="Mr. Gallo") } markbook.add_student_to_classroom(student_Info["John Smith"], classroom_Info["ICS4U"]) assert len(classroom_Info["ICS4U"]["student_list"]) == 1 markbook.remove_student_from_classroom(student_Info["John Smith"], classroom_Info["ICS4U"]) assert type(classroom_Info["ICS4U"]["student_list"]) is list assert len(classroom_Info["ICS4U"]["student_list"]) == 0 assert len(student_Info["John Smith"]["classes"]) == 0
def test_add_student_to_classroom(): """ Dependencies: - create_classroom() """ classroom = markbook.create_classroom(course_code="ICS4U", course_name="Computer Science", period=2, teacher="Mr. Gallo") first_name = "test" last_name = "test" markbook.add_student_to_classroom(first_name, last_name) assert type(classroom["Students"]) is list assert len(classroom["Students"]) == 1
def test_add_student_to_classroom(): """ Dependencies: - create_classroom() """ classroom = markbook.create_classroom(course_code="ICS4U", course_name="Computer Science", period=2, teacher="Mr. Gallo") student = {"first_name": "John", "last_name": "Smith"} assert len(classroom["student_list"]) == 0 markbook.add_student_to_classroom(student, classroom) assert type(classroom["student_list"]) is list assert len(classroom["student_list"]) == 1
def add_student_to_classroom_interface(): classrooms_names = [] with open("data.json", "r") as data: data = json.loads(data.read()) for classroom in data["classrooms"]: # Iterates through classroom to print out all classroom names course_names = classroom["course_name"] classrooms_names.append(course_names) print(*classrooms_names, sep=", ") while True: # Takes input from user try: choice_classroom = input("* Which class would you like to add a student to?(Course name) ") first_name = input("* What is the student's first name? ") last_name = input("* What is the student's last name? ") gender = input("* What is the student's gender? ") student_number = int(input("* What is the student's student number? ")) grade = int(input("* What is the student's current grade? ")) email = input("* What is the student's email? ") marks = list(map(int, input("* What is the student's marks? ").split())) comments = input("* What comments do you have for this student? ") break except ValueError: print(" ---------------------------------------------------------- ") print("| Error, expected a word or a number. |") print(" ---------------------------------------------------------- ") # Dictionary for an individual student student = { "first_name": first_name, "last_name": last_name, "gender": gender, "student_number": student_number, "grade": grade, "email": email, "marks": marks, "comments": comments } for classroom in data["classrooms"]: # Iterate through the data files classroom if choice_classroom == classroom[ "course_name"]: # Check to see if the user's selected classroom is the current iteration # Gets data from the API function added_student = add_student_to_classroom(student, classroom) # Set the classroom as the data returned from the API classroom = added_student with open("data.json", "w") as writer: # Converts the python into json strings data = json.dumps(data, indent=4) # Overwrite the current data with the new added on data writer.write(data) break
def test_class_average(): jayden = markbook.create_student("Jayden", "Smith", "Male", None, 5678910, 10, "*****@*****.**", [50, 60, 70, 80], None) samuel = markbook.create_student("Samuel", "Jiang", "Male", None, 8765432, 10, "*****@*****.**", [90, 30, 70, 50], None) emma = markbook.create_student("Emma", "Winnasdale". "female", None, 9567823, 10, "*****@*****.**", [60, 100, 70, 80], None) classroom = markbook.create_classroom("MHF4U", "Advanced Functions", 3, "Mr.Smith", [], []) markbook.add_student_to_classroom(jayden ,classroom) markbook.add_student_to_classroom(samuel ,classroom) markbook.add_student_to_classroom(emma ,classroom) assert classroom["student_list"] == 3 avg_of_class = markbook.class_average(classroom) assert avg_of_class == 67.5
comments = comments.split(', ') # student info to dict student = { "first_name": student_fname, "last_name": student_lname, "grade": grade, "student_number": student_number, "gender": gender, "email": email, "marks": marks, "comments": comments } # printing new student list print(add_student_to_classroom(student, classroom)) overwrite(copy) break elif page == 5: # remove student clear_screen() print('---REMOVE A STUDENT---') copy = copy() classroom = class_search(copy) if classroom is None: break # getting student student = student_search(classroom) print(student)