Question: Python - I am trying to solve this but I am completely stuck because context before this part (see below) needs to all be within

Python - I am trying to solve this but I am completely stuck because context before this part (see below) needs to all be within one .py file. I don't understand how to use the comprehensions and lambdas here. This is how far I got but I am really confused. Please advise. You can see the question below my script, what I am doing wrong?

Python - I am trying to solve this but I am completely

stuck because context before this part (see below) needs to all be

======JUST TO GIVE CONTEXT=============================

within one .py file. I don't understand how to use the comprehensions

and lambdas here. This is how far I got but I amreally confused. Please advise. You can see the question below my script,what I am doing wrong? ======JUST TO GIVE CONTEXT============================= students ["Smith Johnnie",

students ["Smith Johnnie", "Strauss Jamie", "O'Neill Jack", "Marks Suzie", "Marks Frank", "Marks Annie", "Smith John", "Smith Judy", "Williams Kelly", "Wuilliam Brad"] students.sort(key = Lambda name: name.split(" ")[-1].lower()) print (students) GPA ["3.650", "3.550", "3.250", "3.400", "3.300", "3.900", "3.250", "3.700", "3.400", "3.400"] GPA. sort(reverse True) print(GPA) courses ['CSE-101','CSE-101','CSE-101','CSE-101', 'CSE-102' ,'CSE-101', 'CSE-101', 'CSE-102', 'CSE-101','CSE-102" 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 ,'CSE-102', 'CSE-103', 'CSE-102', 'CSE-103', 'CSE-104' ,'CSE-102', 'CSE-103', 'CSE-103', 'CSE-102', 'CSE-110' 'CSE-201','CSE-202', 'CSE-103', 'CSE-301','CSE-201" ,'CSE-103', 'CSE-210', 'CSE-201', 'CSE-201', 'CSE-125' ,'CSE-220', 'CSE-220', 'CSE-104', 'CSE-302', 'CSE-202" 'CSE-201','CSE-260', 'CSE-210', 'CSE-202', 'CSE-2015 'CSE-325', 'CSE-401', 'CSE-310', 'CSE-203', 'CSE-203" ,'CSE-310', 'CSE-203', 'CSE-203'] set (courses) print(b) Use comprehensions, lambdas and loops to query the student list. . Query 1: o Sort the list by lastName, firstName, both in ascending order, and print the results using printStudents(). Query 2: o Sort the list by GPA in descending order and print the results using printStudents(). Query 3: o Create a set that contains all unique courses taken by all students and print the set. Can use set comprehension (see extra credit). Note: there are 17 unique courses Query 4: Get a list of students who have taken "CSE-201' and print the list using printStudents(). o Must use list comprehension. o Note: there should be 6 students. Query 5: o Get a list of "honor roll" students (GPA >= 3.5) and print the list using printStudents(). Must use list comprehension. Note: there should be 4 students. o o Spyder (Python 3.8) File Edit Search Source Run Debug Consoles Projects Tools View Help CIE: E E >> O part 3.py fraction.py TestSQLite.py read-LastNames.py Lab 5 part 2.py Lab 5 Part 3a.py Lab 5 Part 3b.py untitled 3.py* Redo.py class Student: def _init__(self, id, firstName, lastName, courses = None ): self._id=id self.__firstName - firstName self._lastName = lastName if courses is None: self._courses = dict() else: self._courses = courses == 0: def gpa(self): if len(self.courses.keys()) return 0 else: Tot = 0 for course in self.courses: Tot = Tot + self.courses (course] return (Tot/float(len(self.courses.keys()))) ''def addCourse(self, courseName, score): self._courses.update({ courseName: score})""" 39 40 41 42 43 44 45 46 47 48 49 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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 03 def addCourse(self, course, score): assert isinstance(score, int) "Needs to be an integer: $r' % score assert (score 4), 'Number between @ and 4. self.courses[course) = score self._courses.update({course: score}) "def addCourses(self, courses): self._courses.update (courses) def addcourses(self, courses): assert type(courses) is dict, "No Dictionary." for key in courses: if key not in self.courses.keys(): self.courses[key] = courses [key] #_str_(: #This method should output a formatted string such that printing multiple Student objects will line up. Example result for 3 objects (fields shown: id, lastName, firstName, GPA, courses): def _str_(self):return '%-50 %-155 %-155 %-6.2f %-105 '%(self.id, self.lastName, self.firstName, self.gpa), self.courses) #_repr_O: #We will not directly use this method, but it should have an output similar to _str_. #However, the column formatting is not necessary. You can use commas in between fields: def _repr_(self): return str(self.id) + '' + self.lastName + '/' + self.firstName + ',' + str(self-gpa())+ ',' + self.courses #header() signature: #def header(): #This method returns a string that can used as a header for the results of the _str_method. #Notice that this is a class method because there is no "self" parameter, so it will be called using Student.header(). @classmethod def signature(cls): return '%-55 %-155 %-155 %-65 %-105 '%('ID', "Last Name", "First Name", "GPA", "Courses") return "ID Last Name First Name GPA Courses" + " ========== def getId(self): return self._id def setId(self, id): self._id = id def getFirstName(self): return self._firstName def setFirstName(self, firstName): self._firstName = firstName 94 95 96 97 98 99 100 101 102 103 194 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 def getLastName(self): return self. _lastName def setLastName(self, lastName): self._lastName = lastName def getCourses (self): return self._courses def printStudents (students): print('{:10}'.format('ID'), '{:20}'.format("Last Name'), '{:20}'.format("First Name'), '{:>5}'.format('GPA'), ' Courses') print('================ =========') for student in students: spa=0 courses = student.getCourses() for course in courses: gpa = gpa/float(len(student.getCourses()) gpa += courses[course] print('{:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!