Complete the function best_club, which takes the names of three clubs along with their GBM attendance throughout the semester. The function takes two arguments. The first is a list containing three strings that provide the names of the three clubs, and interleaved with the club names is the attendance figures. We will assume that all clubs given in the list have the same number of meetings. For example, consider the following list:


['SBCS', 29, 16, 11, 15, 32, 'WiCS', 11, 51, 42, 33, 20, 'SBGD', 8, 19, 30, 22, 19]


The three club names are SBCS, WiCS and GDC. Each club had five meetings. SBCS's attendance was 29, 16, 11, 15, 32; WiCS attendance was 11, 51, 42, 33, 20; and SBGD's attendance was 8, 19, 30, 22, 19.


The second argument to the function is simply the number of meetings each club held during the semester. For the example above, this argument would be 5.


Example #1:


gbm_attendance = ['SBCS', 29, 16, 11, 15, 32, 'WiCS', 11, 51, 42, 33, 20, 'SBGD', 8, 19, 30, 22, 19]`

num_meetings = 5

Return value: WiCS



Example #2:


gbm_attendance = ['Chess Club', 56, 11, 15, 32, 'Cuddle Club', 11, 21, 42, 20, 'Yogurt Club', 48, 30, 22, 19]

num_meetings = 4

Return value: Yogurt Club



Example #3:


gbm_attendance = ['Running Club', 56, 41, 90, 11, 15, 32, 'Sitting Club', 11, 21, 42, 20, 11, 19, 'Standing Club', 12, 38, 30, 22, 9, 19]

num_meetings = 6

Return value: Running Club



Example #4:


gbm_attendance = ['Lazy Club', 1, 4, 2, 'Hyperactive Club', 100, 98, 102, 'Mathematical Society', 3, 14, 15]

num_meetings = 3

Respuesta :

The function illustrates the use of loops.

Loops are used for repetitive operations.

The function in Python is as follows, where comments are used to explain each line.

#This defines the function

def best_club(gbm_attendance,num_meetings):

   #This initializes the club and attendance lists

   club = [0]*3;  attendance = [0]*3

   #This initializes a count variable to 0

   count = 0

   #This following iteration gets the names of the clubs from gbm_attendance

   for i in range(3):

       club[i] = gbm_attendance[count]

       count+=num_meetings+1

       

   #This initializes a count variable and the total attendance of each club to 0

   total = 0; count = 0

   #The following iteration calculates the attendance of the first two clubs

   for i in range(1,len(gbm_attendance)):

       if(isinstance(gbm_attendance[i], int)):

           total+=gbm_attendance[i]

       else:

           attendance[count] = total

           count+=1

           total = 0

   

   #The following iteration calculates the attendance of the last club        

   for j in range(2+num_meetings*2+1,len(gbm_attendance)):

       attendance[2] += gbm_attendance[j]

       

   #This initializes the largest attendance to 0

   maxAttendance = 0; maxIndex = 0

   

   #This iterates through the attendance list

   for i in range(3):

       #The following if condition calculates the maximum attendance

       if attendance[i] > maxAttendance:

           maxIndex = i

           maxAttendance =attendance[i]

 

   #This prints the club with the maximum attendance

   print(club[maxIndex])

At the end of the function, the club with the highest attendance is printed.

See attachment for the complete program

Read more about Python programs at:

https://brainly.com/question/22841107

Ver imagen MrRoyal