All problems

Students Carrying Enough Different Courses

mediumPythonSet Logic

You're a data analyst at Ashgrove University. The advising office assigns a faculty advisor to students who need help juggling a timetable, and how heavy a load earns one is a judgement call the head of advising makes each term — some terms she wants everyone carrying two or more different courses, some terms the whole roll, some terms only the students at three or more. However many advisors she has that term is what decides it, so the number is a setting on the report rather than something baked into it.

Two things about the records make this less obvious than it sounds. Enrollment is recorded one row per student, per course, per semester, so a student who retook the same course would appear twice without ever having had two courses to juggle. And one enrollment has no grade against it yet.

students_df — one row per student on the books.

id name major gpa
1 Nora Fischer Computer Science 3.8
2 Omar Haddad Statistics 3.4
3 Petra Novakova Computer Science 3.9
4 Quinn Walsh Mathematics 3.1
5 Ravi Shah Statistics 3.6

enrollments_df — one row per student per course per semester. grade is on a 4.0 scale and is None where no grade has been entered.

student_id course_id grade semester
1 1 3.7 Fall2023
1 2 3.9 Spring2024
2 1 3.2 Fall2023
2 3 3.5 Fall2023
3 2 4.0 Spring2024
3 4 3.8 Spring2024
4 3 2.9 Fall2023
5 1 3.6 Fall2023
5 2 None Spring2024

Input

Both DataFrames above are already built for you — the student and enrollment rows are not read from input. What does arrive is a single line holding a whole number: how many different courses a student must be carrying this term to earn an advisor.

Task: Print a sorted Python list of the names of students enrolled in at least that many different courses. The same course taken in two semesters counts once. An enrollment counts even when no grade has been recorded for it yet. If the bar is set higher than anyone's load, an empty list is the honest answer rather than a bug.

Example: if only Wren Oduya carried enough courses, you'd print ['Wren Oduya'].

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…