(Solved) : Using Python 37 Import Student St Import Random Threshold 001 Tests 0 Passed 0 Def Main Te Q42737339 . . .

USING PYTHON 3.7:

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 s1if grades 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 filenamed filename
# 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()

studentData.txt ->

V00123456, 89
V00123457, 19
V00123458, 30
V00123459, 78

————————-//—————————//—————————–//———————–

class Student:
# constructor
def __init__(self, sid, grade):
self.sid = sid
self.grade = grade

def __str__(self):
return self.sid + ‘:’ + str(self.grade)

def __repr__(self):
return str(self)

def get_sid(self):
return self.sid

def get_grade(self):
return self.grade

def set_sid(self, sid):
self.sid = sid

def set_grade(self, grade):
self.grade = grade

def __eq__(self, other):
if self.sid == other.get_sid():
return True
else:
return False

def main():

print(‘exercise1’)
s1 = Student(‘V00123456’, 90)
print(s1)

s2 = Student(‘V00456789’, 60)
list = [s1,s2]
print(list)

result = s1.get_sid()
print(result)
result = s1.get_grade()
print(result)

s1.set_grade(98)
s1.set_sid(“V00222210”)
print(s1)

s1 = Student(“V0002000”, 89)
print(s1)

s2 = Student(“V0002000”, 67)

print(s2)

s3 = Student(“V0002001”, 67)
print(s3)

print(s1 == s2)
print(s1 == s1)
print(s1.__eq__(s2))
print(s2.__eq__(s3))

s1a = Student(“V0002000”, 89)
s1b = Student(“V0002020”, 65)
#
s2a = Student(“V0002000”, 67)
s2b = Student(“V0002020”, 65)
#
list1 = [s1a,s1b]
list2 = [s2a,s2b]
list3 = [s1a,s2a]
#
print(‘list1==list1’, list1==list1)
print(‘list1==list2’, list1==list2)
print(‘list1==list3’, list1==list3)

main()

Expert Answer


Answer to USING PYTHON 3.7: import Student as st import random THRESHOLD = 0.01 tests = 0 passed = 0 def main(): test_get_higher_g…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?