se the following definitions to answer Questions P3 – P16: You have been asked to represent data for the list of courses offered in a given quarter and the students registered for each course. You should represent each course with the following namedtuple: Course = namedtuple (‘Course’, ‘name department students’) The Course name and department are strings. The Course students is a list of student objects. You should represent each student with the following namedtuple:
Use the following definitions to answer Questions P3 – P16:
You have been asked to represent data for the list of courses offered in a given quarter and the students registered for each course. You should represent each course with the following namedtuple:
Course = namedtuple (‘Course’, ‘name department students’)
The Course name and department are strings. The Course students is a list of student objects.
You should represent each student with the following namedtuple:
Student = namedtuple(‘Student’, ‘name age gpa’)
The Student name is a string, the age is an integer, and gpa is a float..
s1 = Student("Joe", 18, 3.0)
s2 = Student("Jane", 19, 3.2)
s3 = Student("Pete", 20, 2.8)
s4 = Student("Sally", 21, 2.9)
s5 = Student("Matt", 22, 3.3)
s6 = Student("Tina", 20, 3.4)
c1 = Course("CS151", "CS", [s1, s2, s3, s4, s6])
c2 = Course"CS152", "CS", [s1, s5, s3, s2])
c3 = Course("Math2B", "Math", [s6, s5, s4])
AllCourses = [c1, c2, c3]
Q3:AllCourses[1].students[2].age
Q4:len(c2.students)
Q5:s1 in AllCourses[2].students
Q6:AllCourses[1].students[1].gpa
Q7:
Questions P7 and P8 are related to the code skeleton of the function below. The function
enrolledCourses() below takes one student as an argument and returns a list of the courses
which the student is enrolled in.
def enrolledCourses(s):
clist = []
_______[P7]_______
_______[P8]_______
clist.append(c)
return(clist)
The value of [P7]
The value of [P8]
Questions P9 and P10 are related to the code skeleton of the function below. The function numEnrolled() below takes a string cname as an argument and returns the number of students enrolled in the course whose name is cname. The function returns 0 if the course does not exist.
def numEnrolled(cname):
_______[P9]_______
if c.name == cname:
_______[P10]_______
return(0)
The value of [P9]
The value of [P10]
Assume that we want to store all of the Course objects in a dictionary. What should be used as the keys in the dictionary?
def avgGpaCourse(c):
sum = 0
_______[P12]_______
sum = sum + s.gpa
_______[P13]_______
considering a dictionary. Why would using a dictionary be a bad idea in this case?
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)