Part 5: Identify the Active Ciup menpers (10 points) Complete the function find_active_members, which opens and processe
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Part 5: Identify the Active Ciup menpers (10 points) Complete the function find_active_members, which opens and processe
will definetly upvote if works
Part 5: Identify the Active Ciup menpers (10 points) Complete the function find_active_members, which opens and processes a CSV file containing information about club member attendance. A college club on campus holds events a semester, and "active members" are those who attend 3 or more events a semester. The club keeps track of attendance in an input file like so: Name, GBM1, GBM2, GBM3, GBM4, GBM5, GBM6 Jane Doe,1,0,0,1,1,0 John Smith,0,0,1,0,0,0 Anna Lee,0,0,0,0,1,1 Steve Fox, 1,1,1,1,1,1 The function then performs two tasks: 1. It creates a dictionary that maps a student's name (the key of the dictionary) to the number of events the student has attended (the value). 2. It returns a list of the names of all the students who are active members in the club. Hints:
A function sum_list h: ↑ you that takes a list of strings representing integers, converts the strings to actual integers, and returns the sum of those integers. Feel free to use or ignore the function - your choice. The next function will let you proceed through a collection of values one at a time. You might find it useful for skipping over the first row of the CSV file. Assuming that reader stores the return value from the csv.reader function: reader = csv. reader (...) ⠀ then the following code will read the headings from the CSV file and save them in fieldnames: fieldnames = next (reader) Next, the following loop can be used to process the remainder of the CSV file, starting at the first row of actual data (immediately after the row of headings):
Example #1: Contents of members1.csv: Name, GBM1, GBM2, GBM3, GBM4, GBM5, GBM6 Jane Doe,1,0,0,1,1,0 John Smith,0,0,1,0,0,0 Anna Lee,0,0,0,0,1,1 Steve Fox, 1,1,1,1,1,1 Return Value: ['Jane Doe', 'Steve Fox'] Example #2: Contents of members2.csv: Name, GBM1, GBM2, GBM3, GBM4, GBM5 John Smith, 1,1,1,0,0 Jane Doe,1,1,0,1,1 Chris Rock, 0,1,0,0,1 Steve Rogers, 0,1,0,1,1 Thor Odinson, 1, 1, 1, 1,0 Return Value:
Contents of members3.csv: Name, GBM1, GBM2, GBM3, GBM4, GBM5, GBM6, GBM7, GBM8 John Smith,0,0,0,0,0,1,0,1 Jane Doe,1,0,1,0,1,0,1,0 Chris Rock, 0,1,0,0,1,1,0,1 Steve Rogers, 0,1,0,1,1,0,0,0 Thor Odinson,1,1,1,1,0,0,0,0 Donald Duck,0,0,0,0,0,1,1,1 Clark Kent,1,0,0,0,0,1,0,1 Return Value: ['Jane Doe', 'Chris Rock', 'Steve Rogers', 'The Example #4: Contents of members4.csv: Name, GBM1, GBM2, GBM3, GBM4, GBM5, GBM6, GBM7, GBM8, GI John Smith, 1,0,0,0,0,1,0,1,0 Jane Doe,1,0,1,0,1,0,1,0,0 Chris Rock, 0,1,0,0,0,1,0,1,1 Steve Rogers, 0,1,0,0,0,0,0,0,0 Thor Odinson,1,1,1,0,0,0,0,0,1 Donald Duck,0,0,0,0,0,1,0,1,1 lark Kent 1 a aa a 1 a 1 a
Donald Duck,0,0, ,0,0,0,1,0 Clark Kent,1,0,0,0,0,1,0,1,0 Lois Lane,1,0,0,0,1,0,0,1,0 Return Value: ↑ [] import csv 1 B ['John Smith', 'Jane Doe', 'Chris Rock', 'Thor def find_active_members (filename): return 0 # DELETE THIS LINE and sta # Remember: end all of your function # Returns the sum of the values [] list, #strings that represent integers. # Example: sum_list(['1', '0', '0', '1', def sum_list(values): return sum([int (value) for value in # Test cases orint (find_active_members('members1.csv orint (find_active_members('memhers? CSV orint (find_active_members('members.csv orint (find_active_members('me .csv