A high school teacher needs your help! They have been asked to organise a full set of registers for students to take part in some extracurricular activities organised by the school.
There are 100 students in the year group, and each student has selected three preferred activities. Your task is to write a Python program that:
- Allocates each student to an activity
- Prioritises their 1st choice, then 2nd, then 3rd
- Ensures no activity exceeds its maximum capacity
- Identifies any students who could not be allocated
Available Activities
There are 10 activities available:
- Rounders
- Football
- Basketball
- Dance
- Athletics
- Chess Club
- Coding Club
- Arts & Crafts
- Tennis
- Badminton
Each activity has a maximum capacity of 10 students.
The Data
Student choices are stored in a CSV file called choices.csv like this:
FirstName,LastName,Choice1,Choice2,Choice3, James,Bond,Basketball,Athletics,Coding Club, Lara,Croft,Football,Dance,Athletics, ...
The complete file is provided in the Python IDE provided below.
Python Challenge
Your task is to write a Python program that will :
-
Reads the CSV file
Loops through each student
Allocates them:
- First choice if available
Otherwise second choice
Otherwise third choice
Keeps track of:
- Students assigned to each activity
Students who could not be assigned
Example Output
This is what the output of your code would look like:
=== Activity Allocations === Football (10 students) - Lara Croft - John Smith ... Basketball (10 students) - James Bond ... === Unallocated Students === - Alex Turner - Sarah Connor
Hints
Check the following hints to help you plan your solution!
- Use a dictionary to store activities and their current student lists
- Use the csv module to read the file
- Think carefully about how to check if an activity is full
- You may want a separate list for unallocated students
Python Code
We have started the code to help you read and extract the data from the CSV file. Your task is now to complete this code to allocate each students to an activity based on their preferences when possible.

Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area






