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:

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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?

Course department
Course name
Course students
Student gpa
 
Questions P12 and P13 are related to the code skeleton of the function below. The function avgGpaCourse() below takes a Course object as an argument and returns the average GPA of the students enrolled in the course.
def avgGpaCourse(c):
    sum = 0
    _______[P12]_______
          sum = sum + s.gpa
     _______[P13]_______
The value of [P12]
Afor s in c.students:
Breturn(sum/cnt)
Cif s in c.students:
Dreturn(sum/len(c.students))
The value of [P13]
Afor s in c.students:
Breturn(sum/cnt)
Cif s in c.students:
Dreturn(sum/len(c.students))
Suppose that we need to store all Student objects in a single data structure and we are
considering a dictionary. Why would using a dictionary be a bad idea in this case?
A,There is no key which is guaranteed to be unique.
B,Integers and floats cannot be used as keys.
C,Accessing a dictionary is slower than other data structures, like a list.
D,Dictionaries cannot be used to store nametuples.
 
Suppose that we need to store all Student objects in a single data structure and we are considering using a list. One operation that we need to perform often is finding the average GPA of all students. Is the following statement true, “A list is good for this purpose because its elements are ordered, and that makes the computation of average GPA fast”?
TURE/FALSE
 
Let’s say that a new Student registers for a Course. In that case, we would need to add the new Student object to the students field of the appropriate Course object. Is the following statement true, “A new Student object cannot be added to the students field of a Course object because namedtuples are immutable”?
TURE/FALSE
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY