Search for question
Question

You are a representative for a school outreach programme and have enough time to talk to five classes during a school visit. In the school, there are 25n25 different classes, N

pupils, and each pupil belongs to exactly three classes. Note that the classes may not necessarily be of the same size. Assume each pupil has a unique integer ID from 0 to -IN-1. You are given a list of classes, where each element classes[i] contains a list of pupil IDs. So, if a particular pupil (e.g. ID 4) is in classes 0 and 6, then the lists classes [0] and classes [6] will both contain 4. In each class, you are able to talk to all the pupils in the class. You want to talk to as many different pupils within the m classes that you choose. One defined function for each part, and add comments for each line of the code Part 1: def generate_classes_bad(n, N): import random students list (range (N)) # Initialise list of n empty classes classes = [] for c in range(n): classes.append( []) class_size = round (N/n) * 3 for i in range (N): this class = random. sample (students, class_size) classes [i] = this_class return classes generate_classes_bad(5, 6) find the mistakes Write your own version of generate_classes that fixes these issues and randomly generates a valid list of classes./nPart 2: Write a function select_classes that takes classes list as argument, and selects five classes to talk to, with the aim of talking to as many different pupils as possible. Your function should return the list of class IDs, e.g. [0, 2, 4, 8, 9], and the number of pupils reached. Your function does not need to be optimal in the sense that it is guaranteed to talk to the most pupils possible, but it should at least be well motivated. You should test your code on a couple of simple examples to check that it is working. Hint: if you want to remove the duplicates of a list 1, you are allowed to do 1 = list(set(1)). Hint: See Lab 3 for a reminder of how to write a function that returns multiple values. Part 3: Write a short Markdown paragraph explaining how the code works and explain either i) why your solution is guaranteed to return the best possible list of classes, or ii) why it is a reasonable idea even if not optimal, and a counter-example where it fails to find the best possible list of classes.

Fig: 1

Fig: 2