USING PYTHON 3.7:
studentData.txt ->
V00123456, 89
V00123457, 19
V00123458, 30
V00123459, 78
import Student as st
import random
THRESHOLD = 0.01
tests = 0
passed = 0
def main():
test_get_higher_grade_student()
test_is_grade_above()
test_get_students()
test_get_classlist()
# test_count_above()
# test_get_average_grade()
print(“TEST RESULTS:”, passed, “/”, tests)
def test_get_higher_grade_student():
s1a = st.Student(“V0002000”, 89)
s1b = st.Student(“V0002001”, 89)
s2 = st.Student(“V0002002”, 67)
s3 = st.Student(“V0002002”, 97)
result = get_higher_grade_student(s1a,s1b)
print_test(“get_higher_grade_student(s1a,s1b)”, result== s1a)
result = get_higher_grade_student(s1a,s2)
print_test(“get_higher_grade_student(s1a,s1b)”, result== s1a)
result = get_higher_grade_student(s1a,s3)
print_test(“get_higher_grade_student(s1a,s1b)”, result== s3)
# (Student, Student -> bool)
# returns the Student with higher grade of s1 and s2, or s1 ifgrades are equal
def get_higher_grade_student(s1, s2):
print(“fix me”)
# TODO: complete get_higher_grade_student
# this should not always return s1
return s1
def test_is_grade_above():
s1 = st.Student(“V0002000”, 89)
s2 = st.Student(“V0002002”, 67)
result = is_grade_above(s1, 89)
print_test(“is_grade_above(s1, 89)”, result ==False)
result = is_grade_above(s1, 88)
print_test(“is_grade_above(s1, 89)”, result ==True)
result = is_grade_above(s2, 50)
print_test(“is_grade_above(s2, 50)”, result ==True)
result = is_grade_above(s2, 80)
print_test(“is_grade_above(s2, 80)”, result ==False)
# (Student, int -> bool)
# returns True if the grade of Student s is above the giveninteger
def is_grade_above(s, n):
print(“fix me”)
# TODO: complete is_grade_above
def test_get_students():
result = get_students(‘studentData.txt’)
expected = [st.Student(‘V00123456’,89),st.Student(‘V00123457’, 99),
st.Student(‘V00123458’, 30),st.Student(‘V00123459’,78)]
print_test(“result = get_students(‘studentData.txt’)”,result == expected)
# (str -> (list of Student))
# creates a new list of Students from data in the file namedfilename
# where each line of file has a sid and grade separated by acomma
def get_students(filename):
print(“fix me”)
# TODO: complete get_students
def test_get_classlist():
students = []
result = get_class_list(students)
expected = []
print_test(“result = get_classlist(students)”, result== expected)
students = [st.Student(‘V00123456’,89),st.Student(‘V00123457’, 99),
st.Student(‘V00123458’, 30),st.Student(‘V00123459’,78)]
result = get_class_list(students)
expected =[‘V00123456′,’V00123457′,’V00123458′,’V00123459’]
print_test(“result = get_classlist(students)”, result== expected)
# ((list of Student) -> (list of str))
# returns a new list of Students ids for each Student instudents
def get_class_list(students):
print(“fix me”)
# TODO: complete get_classlist
# TODO:
# Design and test a function that will take a list ofStudents
# and a grade and counts and return the number of Students
# who have a grade above the given grade
# TODO:
# Design and test a function that will take a list ofStudents
# computes and returns the average grade of all Students instudents
# (str, bool -> None)
# prints test_name and “passed” if expr is True otherwise prints”failed”
def print_test(test_name, expr):
global tests
global passed
tests += 1
if(expr):
print(test_name + ‘: passed’)
passed += 1
else:
print(test_name + ‘: failed’)
# The following code will call your main function
# It also allows our grading script to call your main
# DO NOT ADD OR CHANGE ANYTHING PAST THIS LINE
# DOING SO WILL RESULT IN A ZERO GRADE
if __name__ == ‘__main__’:
main()
Expert Answer
Answer to USING PYTHON 3.7: studentData.txt -> V00123456, 89 V00123457, 19 V00123458, 30 V00123459, 78 import Student as st import…