Need a .py file by the end of the dayCreating functions with lists, tuples, sets
CS602- Data-Driven Development with Python Spring’2021 Programming Assignment 4 1 Programming Assignment 4 Getting started Complete the reading and practice assignments posted on the course schedule. Review class handouts and examples. This assignment is designed to emphasize working with files and directories, use of dictionaries, tuples, sets and lists. Programming Project: Eligibility worth: 20 points Estimate number of students eligible for a certificate. Data and program overview In this assignment you will be working with data on student enrollment in classes of the Boston School of Magic. The data includes: • Files that list which courses comprise certificate programs of the school. Descriptions programs include program name and a listing of required classes, provided in files named programX.txt, where X is a number, such as in program1.txt For example, program1.txt contains the following description of the HA1 (Hogwarts Abroad 1) certificate program: HA1 1001 Transfiguration. 1100 Charms. 1250 Defense Against the Dark Arts. Please note that o number of program files may be different, however, all program files are named as described above o name of a program in the first line may consist of any number of words. • Class lists, including grades of students who took these courses in the past as well as those who are taking the courses now. Each class list comes in a separate file, the first line of which includes the course number, preceded with letter ‘c’, e.g. c1250. Each such file stores records of students who were/are enrolled in course number 1250. Those files that contain -1 instead of a grade are current semester files, for which grades have not been posted yet. There is a lot of useful information that can be derived from this data. In this assignment, you will be creating a program that uses this data to determine the students who will be eligible for a certificate in the end of the current semester. A student is eligible for a certificate in a specified program if s/he has completed all courses required for the program. I provide two data sets for this assignment, in zip files called data-small-21.zip and data-large-21.zip. Download and unzip the files in your project folder. Upon unzipping, two folders files-small and files-large should be added to your project folder. Review the contents of the files before you start, to familiarize yourself with their structure. Furthermore, you should create your own test set with a small number of data files for the initial testing purposes. CS602- Data-Driven Development with Python Spring’2021 Programming Assignment 4 2 The program that you write must work as follows. 1. Ask the user to specify the subfolder in the current working directory, where the files are stored. 2. Ask the user for a certificate program name, outputting a sorted list of login names of students that have taken all of the courses required for the specified program and are thus eligible to receive the program certificate. Incorrect program names should be ignored and the program should go on. When the user does not specify any input, pressing enter instead, the program must stop. The two sample interactions demonstrate the running of the program. User input is marked in boldface. Sample interaction: Please enter the name of the subfolder with files: files-small Enter program name or press enter to stop: HA1 5 students are eligible for degree in HA1 awillowbend cwashneys ibogandale ktarrs lhazlebury Enter program name or press enter to stop: HA2 0 students are eligible for degree in HA2 Enter program name or press enter to stop: MBA Enter program name or press enter to stop: Bye! Here is one more: Please enter the name of the subfolder with files: files-large Enter program name or press enter to stop: HA5 8 students are eligible for degree in HA5 acarnene dstrieff elochdon fstonor icourtwright iphalen lbuckhannon mgainswood Enter program name or press enter to stop: Bye! Important Notes and Requirements 1. Your program should not use any global variables and should have no code outside of function definitions, except for a single call to main. 2. All file related operations should use device-independent handling of paths (use os.getcwd() and os.path.join() functions to create paths, instead of hardcoding them; use os.listdir() to obtain a list of all files in a folder). 3. You must define and use functions specified below in the Required Functions section. You may define other methods as appropriate. 4. You should use data structures effectively to efficiently achieve the goals of your functions. CS602- Data-Driven Development with Python Spring’2021 Programming Assignment 4 3 Required Functions You must define and use the following functions, plus any others as you see fit. When developing functions, remember to test each one before moving to develop another. a. Function processOneProgramFile(), which must be passed a single parameter of type str, providing the path to a program description file described in the Data and program overview section. The function should construct a dictionary based on the information in the file. The dictionary should have keys equal to the course numbers, and values for keys equal to the corresponding course titles, e.g. {'1001': 'Transfiguration.', '1100': 'Charms.', '1250': 'Defense Against The Dark Arts.'}, The function must return a tuple, consisting of the program name and the created dictionary, e.g. ('HA1', {'1001': 'Transfiguration.', '1100': 'Charms.', '1250': 'Defense Against The Dark Arts.'} ) b. Function processProgramFiles(). This function will help in combining the data about individual programs into a single dictionary. It must be passed a single parameter, defining the subfolder with the program files. It must call function processOneProgramFile() to process individual files that are named ‘programX.txt’ , where X is a number. The return values from these calls must be used to construct a dictionary in which the program name is used for the key and program courses dictionary is the corresponding value, e.g. { 'HA1': {'1001': 'Transfiguration.', '1100': 'Charms.', '1250': 'Defense Against The Dark Arts.'}, 'HA2': {'2300': 'Care Of Magical Creatures.', '2470': 'Magical Theory', '2600': 'History Of Magic.', '1100': 'Charms.'}, . . . } The function must return the created program dictionary. c. Function processClassFiles():This function will help in combining the data about enrollments into courses from multiple files into a single dictionary organized by course number. It must be passed a single parameter, defining the subfolder with the class list files described in the Data and program overview section. The function should construct a dictionary, which we will call class-student dictionary, with keys corresponding to course numbers. The value for each key must be equal to the set of student login for students who have taken or are currently taking the course designated by the key. The function must return the constructed class-student dictionary. d. Function allStudents(), which is passed the class-student dictionary and calculates and returns a set of all students that ever took a class. e. Function eligibleStudents(), which will be used to compose a sorted list of students eligible for a certificate. This function must be passed four parameters: the certificate program name, the program dictionary, the class-student dictionary and the set of all students. CS602- Data-Driven Development with Python Spring’2021 Programming Assignment 4 4 The function must return a sorted list of students who would be eligible for the certificate in the program specified by the parameter, i.e. have taken all of the courses the program requires (this includes students currently taking courses). If the parameter does not refer to a valid course number, the function should return an empty list. f. Function main(), which will be called to start the program and works to create the needed dictionaries, calculate the set of all students and run a loop, reporting the eligible students demonstrated in the interaction. Grading The grading schema for this project is roughly as follows: Your program should compile without syntax errors to receive any credit. If a part of your program is working, you will receive partial credit, but only if the program compiles without syntax errors. Your program will be graded on the correctness of the output, and conformance to the requirements, including requirements on functions. 2 points will be awarded for good programming style, as defined in handout 1 Created by Tamara Babaian on March 24, 2021 Programming Assignment 4 Programming Assignment 4 Getting started Getting started Programming Project: Eligibility worth: 20 points Programming Project: Eligibility worth: 20 points Data and program overview Data and program overview Sample interaction: Sample interaction: Important Notes and Requirements Important Notes and Requirements Required Functions Required Functions Required