using the Assignment1 sample, please help me with the requirements below. (I was not able to paste the codes since it ex

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

using the Assignment1 sample, please help me with the requirements below. (I was not able to paste the codes since it ex

Post by answerhappygod »

using the Assignment1 sample, please help me with therequirements below. (I was not able to paste the codes since itexceeds the word limit)
Using The Assignment1 Sample Please Help Me With The Requirements Below I Was Not Able To Paste The Codes Since It Ex 1
Using The Assignment1 Sample Please Help Me With The Requirements Below I Was Not Able To Paste The Codes Since It Ex 1 (101.11 KiB) Viewed 35 times
Assignment 1 sample:
Using The Assignment1 Sample Please Help Me With The Requirements Below I Was Not Able To Paste The Codes Since It Ex 2
Using The Assignment1 Sample Please Help Me With The Requirements Below I Was Not Able To Paste The Codes Since It Ex 2 (61.67 KiB) Viewed 35 times
test_main.py:
You will be continuing with your script and modules from Assignment 1. You will be adding file input/output, some minor upgrades and one additional report type. You may continue with your submission from Assignment 1 (preferred) or use the sample Assignment 1 implementation on D2L. Use the same patterns from Assignment 1 for your implementation of Assignment 2. Your assignment must have no syntax errors and must successfully run (i.e., no runtime errors) for all combinations of the above inputs and outputs AND against the provided unit test. If the script cannot be run, you will receive a mark of zero on this assignment. Requirements The following table identifies the changes required for this assignment. Requirement Update the data.py module so that the get_student_grades function gets its list of student grades from the given data.csv file: The student data from data.csv should be read in the program as a list, where each line in the file is an element in the list. • Any extra line returns should be removed from the end of each element. • The returned list of strings should be identical in format to the previous implementation Course Report Updates The course report will be updated with the top 3 and bottom 3 grades in the course: > main.py course COMP1516 Report: Course: Number Students: Lowest Grade: Highest Grade: 2022-03-02 06:42:24 COMP1516 40 20.2 99.3 Marks 2 1
Average Grade: Median Grade: Top 3 Grades: 99.3, 98.5, 98.5 Bottom 3 Grades: 32.2, 25.2, 20.2 76.0 86.2 The top/bottom 3 grades should be displayed from highest to lowest. Hint: Sort and slice your grades list. Student Report Updates The student report will be updated with the courses the student is enrolled in: > main.py student A0001000 Report: Student: Number Courses: 2022-03-02 06:46:59 A0001000 3 Courses: COMM1000, COMP1516, MATH1305 Lowest Grade: 90.9 Highest Grade: 98.5 Average Grade: 94.2 GPA: 4.0 The courses should be sorted alphabetically. You will add support for one new report type to the command line arguments: course, student and school If the report type is not one of the above types, the error message will be: Invalid report type. Must be course or student or school. If the report type is school, then the second argument will be the school name. The school name must be alphanumeric and 4 characters or more in length. If not, the error message will be: School name must be alphanumeric and at least 8 characters. And example run of the program for a school report would look like: >main.py school BCIT 1 1
New School Report The new school report shows summary information for all courses. It should display as follows for the given data in student grades: > main.py school School Name Report: School: Number Courses: Courses: Number Students: Top Student: Top Grade: Bottom Student: Bottom Grade: 2022-03-02 06:49:54 SchoolName 3 COMM1000, COMP1516, MATH1305 40 A0001007 99.3 A0002209 20.2 The School line displays the school name from the command line. Number of Courses and Courses are the number and list of courses in the school (i.e., all the unique courses in the student grades data). Number of Students is the number of unique students in all the courses in the school. The Top Student is one with the highest grades across all the courses. The Bottom Student is the one with the lowest grade across all the courses. The new School report should be printed to the console AND written to a file named as follows: 2 1
the school. The Top Student is one with the highest grades across all the courses. The Bottom Student is the one with the lowest grade across all the courses. The new School report should be printed to the console AND written to a file named as follows: .txt So for a school name of BCIT the filename would be bcit.txt The provided unit tests (test_main.py) must run and all pass to verify the above requirements. You may have to tweak the report output to get the unit tests to pass. Make sure your program works both on the command line and with the unit tests (test_main.py). The majority of your marks will come from the fully passing unit tests. 1 10
ve\Deskto 1 2 3 4 5 on 00 a 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 grade_stats.py X data.py main.py X reports.py X def get student_grades (): """Gets and returns the list of all student grades, as a list of strings student grades 1 Į "COMP1516, A0001000, 98.5", "COMP1516, A0001001, 56.4", "COMP1516, A0001002,45.6", "COMP1516, A0001003, 96.0", "COMP1516, A0001004,88.7", "COMP1516, A0001005, 74.3", "COMP1516, A0001006,90.1", "COMP1516, A0001007,99.3", "COMP1516, A0001008, 20.2", "COMP1516, A0001009,85.8", "COMP1516, A0001010, 98.5", "COMP1516, A0001011, 56.4", "COMP1516, A0001012,45.6", "COMP1516, A0001013,96.0", "COMP1516, A0001014,88.7", "COMP1516, A0001015,74.3", "COMP1516, A0001016,90.1", "COMP1516, A0001017,99.3", "COMP1516, A0001018,20.2", "COMP1516, A0001019,85.8", "COMP1516, A0002201,48.5", get_student grades() 31 31 31
Deskto 1 NA 2 3 4 5 6 7 ∞o a 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 grade_stats.py X data.py import statistics A A TH def calculate_course_statistics (course, student_grades): """ Calculates the statistics for a single course main.py X reports.py X course_exists = False num_students = 0 average_grade = 0.0 median_grade = 0.0 min_grade = 0.0 max_grade = 0.0 course_grades = [] for student in student_grades: student_data = student.split(",") if student_data[0] == course: course_exists = True num_students += 1 A if course_exists: course_grades.append(float(student_data[2])) average_grade = statistics.mean (course_grades) median_grade = statistics.median (course_grades) min_grade = min (course_grades) max_grade = max(course_grades)
to grade_stats.py data.py X main.py X reports.py X A return course_exists, num_students, average_grade, median_grade, min_grade, max_grade 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 def convert_to_gpa (percentage_grade): """ Converts a percentage grade to a gpa gpa = 0.0 if percentage_grade >= 85: gpa = 4.0 elif percentage_grade >= 80: gpa = 3.7 elif percentage_grade >= 76: gpa = 3.3 elif percentage_grade >= 73: gpa = 3.0 elif percentage_grade >= 70: gpa = 2.7 elif percentage_grade >= 67: gpa = 2.3 elif percentage_grade >= 64: gpa = 2.0 elif percentage_grade >= 60: gpa = 1.7 elif percentage_grade >= 55:
o 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 grade_stats.py X data.py X A -D A main.py elif percentage_grade >= 55: gpa = 1.5 elif percentage_grade >= 50: gpa = 1.0 else: gpa = 0.0 return gpa def calculate_student_statistics (student_num, student_grades): """ Calculates the statistics for a single student student_exists = False num_courses = 0 average_grade = 0.0 min_grade = 0.0 max_grade = 0.0 = 0.0 reports.py X gpa grades [] for student in student grades: student_data = student.split(",") if student_data[1] == student_num: student_exists = True num_courses += 1
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 grade_stats.py x data.py x main.py X average_grade = 0.0 A A min_grade = 0.0 max_grade = 0.0 gpa = 0.0 grades = [] reports.py X for student in student_grades: student_data = student.split(",") if student_data[1] == student_num: student_exists = True num_courses += 1 grades.append(float(student_data[2])) if student_exists: average_grade = statistics.mean(grades) min_grade min (grades) max_grade = max (grades) gpa = convert_to_gpa (average_grade) return student_exists, num_courses, average_grade, min_grade, max_grade, gpa
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 grade_stats.py X data.py X import data import grade_stats import reports A A Ą A import sys def main(): main.py if len(sys.argv) != 3: print("Invalid number of arguments.") exit(0) report_type sys.argv[1] reports.py X if report_type != "course" and report_type != "student": print("Invalid report type. Must be course or student.") exit(0) student_grades = data.get_student_grades () if report_type == "course": course_id = sys.argv[2] course_exists, num_students, average_grade, median_grade, min_grade, max_grade grade_stats.calculate_course_statistics (course_id, student_grades) = 1
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 grade_stats.py data.py Xmain.py X reports.py X course_id = sys.argv[2] D A course_exists, num_students, average_grade, median_grade, min_grade, max_grade grade_stats.calculate_course_statistics (course_id, student_grades) reports.display_course_statistics (course_id, course_exists, num_students, average_grade, median_grade, elif report_type == "student": student_id = sys.argv[2] student_exists, num_courses, average_grade, lowest_grade, highest_grade, gpa (student_id, student_grades) grade_stats.calculate_student_statistics min_grade, max_grade) reports.display_student_statistics (student_id, student_exists, num_courses, average_grade, lowest_grade, highest_grade, else: print("Invalid report type") gpa) = 1 1
1 2 3 4 5 6 7 8 0 3 4 5 6 7 8 9 0 1 2 3 4 5 grade_stats.py Đ import datetime A data.py X main.py X def display_course_statistics (course_name, course_exists, num_students, average_grade, median_grade, min_grade, max """ Displays the statistics for the specified course """ if course_exists: print("Report: print("Course: print("Number Students: print("Lowest Grade: print("Highest Grade: print("Average Grade: print("Median Grade: else: reports.py %s" % datetime.datetime.now().strftime ("%Y-%m-%d %H:%M: %S")) %s" % course_name) %d" % num_students) %.1f" % min_grade) %.1f" % max_grade) %.1f" % average_grade) %.1f" % median_grade) print("Course %s does NOT exist!" % course_name) print("Report: print("Student: def display_student_statistics (student_num, student_exists, num_courses, average_grade, lowest_grade, highest_grade """ Displays the statistics for the specified student """ if student_exists: ⠀ A 3 A V %s" % datetime.datetime.now().strftime ("%Y-%m-%d %H:%M:%S")) %s" % student_num) print("Number Courses: %d" % num_courses) print("Lowest Grade: %.1f" % lowest_grade) print("Highest Grade: %.1f" % highest_grade)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 grade_stats.py A A A A main.py data.py print("Highest Grade: print("Average Grade: print("Median Grade: else: print("Course %s does NOT exist!" % course_name) reports.py %.1f" % max_grade) %.1f" % average_grade) %.1f" % median_grade) def display_student_statistics (student_num, student_exists, num_courses, average_grade, lowest_grade, highest_grade """ Displays the statistics for the specified student """ if student_exists: %s" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M: %S")) print("Report: print("Student: %s" % student_num) print("Number Courses: %d" % num_courses) print("Lowest Grade: %.1f" % lowest_grade) print("Highest Grade: print("Average Grade: print("GPA: else: %.1f" % highest_grade) %.1f" % average_grade) %.1f" % gpa) ⠀ A3 ^ v print("Student ID %s does NOT exist!" % student_num) O
nment 2 test_main.py grade_stats.py X to 1 aimport ... 8 9 10 11 12 13 14 15 of 16 17 18 19 20 21 22 23 24 25 26 e 27 28 ▶ A 29 30 data.py X class TestMain (TestCase): correct_output = 0 correct_errors = 0 main.py @classmethod def setUpClass (cls): @classmethod """ Sets up the Test Case """ TestMain.correct_output = 0 TestMain.correct_errors = 0 print("Grading your Main Script... ") def tearDownClass(cls): test_main.py if _name__ == "_main_" """ Tears down the Test Case "" print("Number of correct script outputs: %d/7" % TestMain.correct_output) print("Number of correct script error handling: %d/3" % TestMain.correct_errors) def test_main_invalid_report_type(self): """ main.py invalid COMP1516 """ saved_stdout = sys.stdout reports.py ⠀ A4 A4 9 v
nent 2 / test_main.py grade_stats.py 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 5% ♡ 8 A A @ A data.py saved_stdout try: out = io.String10 () sys.stdout = out sys.argv = [ ] main.py = sys.stdout "main.py", "invalid", "COMP1516" except SystemExit as e: finally: test_main.py main.main() print("No error on output type and exit(0)") reports.py X output = out.getvalue().strip () self.assertEqual (output, "Invalid report type. Must be course or student or school.") TestMain.correct_errors += 1 sys.stdout = saved_stdout if_name__ == "_main_" Ĥ def test_main_invalid_school_name_on_length(self): """ main.py school sch "** saved stdout = sys stdout A4 A4 9^v
test_main.py grade_stats.py X 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 A Ą A 보 data.py X main.py saved_stdout=sys.stdout try: out = io.StringI0 () sys.stdout = out sys.argv = [ ] "main.py", "school", "sch" except SystemExit as e: test_main.py main.main() print("No error on output type and exit(0)") finally: reports.py output = out.getvalue().strip () self.assertEqual (output, "School name must be alphanumeric and at least 4 characters.") TestMain.correct_errors += 0.5 sys.stdout = saved_stdout A4 A4 9^v def test_main_invalid_school_name_on_alnum (self): """ main.py school A$%^&*A """ TestMain test main invalid report type() > try
ent 2 test_main.py grade_stats.py 78 79 80 81 82 83 84 85 86 87 88 A A A A A data.py saved_stdout TestMain ✔ Python Packages try: out = io.StringIO () sys.stdout = out sys.argv = [ ] 89 90 91 92 93 94 95 96 97 98 99 00 01 ▶ E def test_main_invalid_number_arguments (self): A2 main.py X = sys.stdout "main.py", "school", "A$%^&*A" test_main.py main.main() print("No error on output type and exit(0)") except System Exit as e: finally: reports.py X output = out.getvalue().strip () self.assertEqual (output, "School name must be alphanumeric and at least 4 characters.") TestMain.correct_errors += 0.5 sys.stdout = saved_stdout """ main nu course """ test_main_invalid_school_name_o... Python Console A4 A4 9 ^ V O Event Log 54:34 LF UTF-8 4 spaces Python 3.10 (assignment 1 sample)
ent 2 test_main.py grade_stats.py 02 03 04 05 _06 07 08 09 10 11 12 13 14 E É A A B 15 16 17 18 19 20 21 22 23 24▶ B 25 A A data.py main.py """ main.py course """ saved_stdout=sys.stdout TestMain try: out= io.String10 () sys.stdout = out sys.argv = [ ] "main.py", "course" except SystemExit as e: main.main() print("No error on output type and exit(0)") finally: test_main.py output = out.getvalue().strip() self.assertEqual (output, "Invalid number of arguments.") TestMain.correct_errors += 1 sys.stdout = saved_stdout def test_course_output_valid(self): """ main.py course COMP1516 """ mcca al m de alta de L reports.py X test_main_invalid_school_name_o... A4 A4 9 Database SciView
ignment 2 test_main.py grade_stats.py kto 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 minal A 보 Ĥ data.py saved_stdout= sys.stdout TestMain Python Packages try: main.py out io.String10 () sys.stdout = out sys.argv = [ ] test_main.py "main.py", "course", "COMP1516" main.main() output = out.getvalue() expected_output = """^Report: COMP1516 Course: Number Students: 40 Lowest Grade: 20.2 Highest Grade: 99.3 Average Grade: 76.0 Median Grade: 86.2 Top 3 Grades: 99.3, 98.5, 98.5 Bottom 3 Grades: 32.2, 25.2, 20.2\s*$""* reports.py X test_main_invalid_number_argume... try Python Console \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} sys.stdout = saved_stdout self._compare_output (expected_output, output) TestMain.correct_output += 1 A4 A4 9 ^ Y Event Log
G 6 assignment 2 test_main.py ✿ - grade_stats.py X ive\Deskto 151 152 153 154 ► A 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 Terminal A A A A A data.py X main.py finally: ✔ Python Packages sys.stdout = saved_stdout def test_course_output_invalid_course (self): """ main.py course COMP1234 *** saved_stdout = sys.stdout try: out io.String10 () sys.stdout = out sys.argv = [ ] test_main.py X = "main.py", "course", "COMP1234" finally: reports.py X main.main() output = out.getvalue() expected_output = """^Course COMP1234 does NOT exist!\s*$""" sys.stdout = saved_stdout self._compare_output (expected_output, output) TestMain.correct_output += 1 sys.stdout = saved_stdout TestMain > test_main_invalid_number_argume... > try Python Console A4 A4 9 ^ V Event Log Database # SciView
ent 2 test_main.py grade_stats.py x data.py 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 B F main.py saved_stdout = sys.stdout Ą try: out = io.String10 () sys.stdout = out sys.argv = [ ] "main.py", "school", "BCIT" if os. path.exists("bcit.txt"): os.remove("bcit.txt") School: Number Courses: Courses: Number Students: test_main.py main.main() output = out.getvalue() expected_output = """^Report: BCIT 3 COMM1000, COMP1516, MATH1305 40 Top Student: A0001007 Top Grade: 99.3 Bottom Student: A0002209 Bottom Grade: 20.2\s*$""" TestMain test_main_invalid_number_argume... > try reports.py X \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} A4 A4 9 ^ Database Sciv
nment 2 - grade_stats.py to 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 test_main.py 223 224 225 226 227 A Đ A A data.py main.py x sys.stdout = saved_stdout self._compare_output (expected_output, output) TestMain.correct_output += 1 TestMain finally: if os. path.exists("bcit.txt"): fh = open("bcit.txt") file_output = fh.read() fh.close() try: test_main.py A def test_student_output_valid(self): """ main.py student A0001000 """ saved_stdout=sys.stdout self._compare_output (expected_output, file_output) TestMain.correct_output += 2 os.remove("bcit.txt") sys.stdout = saved_stdout out io.String10 () sys.stdout = out sys.argv = [ "main ny" test_school_output_valid() try reports.py X A4 A4 9 ^ ⠀ Database SciView
nment 2 test_main.py grade_stats.py X co 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 data.py X sys.argv = [ ] Student: Number Courses: Courses: Lowest Grade: Highest Grade: Average Grade: AGPA: main.py "main.py", "student" "A0001000" main.main() output = out.getvalue() expected_output = """^Report: A0001000 finally: 3 test_main.py COMM1000, COMP1516, MATH1305 90.9 98.5 94.2 4.0\s*$""" reports.py X sys.stdout = saved_stdout self._compare_output (expected_output, output) TestMain.correct_output += 1 sys.stdout = saved_stdout \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} def test student_output_invalid_student (self): TestMain test_school_output_valid( finally A4 A4 9 AV Database Sciv
nt 2 test_main.py -1 2 3 4 5 6 7 8 9 -0 -1 2 3 -4 5 6 -7 8 9 0 1 2 3 -4 grade_stats.py -5 A A data.py main.py X test_main.py saved_stdout sys.stdout TestMain ✔Python Packages try: out io.String10 () sys.stdout = out sys.argv = [ ] "main.py", "student", "A0001234" main.main() output = out.getvalue() expected_output = """^Student ID A0001234 does NOT exist!\s*$""" finally: sys.stdout = saved_stdout self._compare_output (expected_output, output) TestMain.correct_output += 1 reports.py X sys.stdout = saved_stdout def _compare_output(self, expected_output, actual_output): """ Compares the expected against the actual """ expected_lines = expected_output.strip().split("\n") output_lines = actual_output.strip().split("\n") test_student_output_valid() try Python Console ⠀ A4 A4 9 ^ v Event Log Database
ment 2 test_main.py LIZ grade_stats.py 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 A A A A test_main.py _vwmpuiv_www.ver, expoocca_00cpoL, MULUUL_ww.pus. """ Compares the expected against the actual """ expected_lines = expected_output.strip().split("\n") output_lines = actual_output.strip().split("\n") data.py main.py self.assertEqual(len (expected_lines), len(output_lines), reports.py "Expected %d lines of output but got %d" % (len (expected_lines), len (output_lines))) for line_num in range(0, len(expected_lines)): if re.search(expected_lines [line_num], output_lines [line_num]) is None: print("Expected at Line %02d: %s" % (line_num, expected_lines [line_num])) print("Actual Output : %s" % output_lines [line_num]) self.assertIsNotNone (re.search(expected_lines [line_num], output_lines [line_num]), "Line %d of output doesn't match" % line_num) if __name__ == "__main__": unittest.main() TestMain >test student output invalid stu... > try ⠀ A4 A4 9 ^ V
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply