CS105: Computer Programming: PYTHON Project 05 Assigned on Wednesday, November 14, 2007 Due on Tuesday, November 20 at 11:59PM ============= 1. Objectives ============= As before, we start with an initial python code ("sort_algorithm.py"). in this project, we are requested to modify the code or add some functions to do the following main tasks. (1) Handling commandline arguments; (2) Checking user inputs (i.e., commandline arguments) using regular expression; (3) File input and output. Some NOTEs for this project: (1) Don't modify the sort functions given in the code, but just use (i.e., call) them as the examples shown in the code. (2) We can freely modify or add remaining code, so feel free to implement your own functions in order to perform the required functions, specified below. (3) Make sure the following line and other testing statements as added at the end of each file for a unit test: if __name__ == '__main__': ============== 2. Description ============== We will do the following detailed requirements that are related with commandline arguments and corresponding functions (2.1) You have the following commandline arguments to process: -a m, s, i, q, or h It specifies an initial of each algorithm. Each (in order) stands for merge_sort(), bubble_sort(), selection_sort(), insertion_sort(), quick_sort(), and heap_sort(). Note that user can type a capital letter, so ignore the case. Note that each algorithm first needs to have input integer values unsorted, sort them in an increasing order, then store the resulting sorted values in the specified (or default) output file (see option "-o" for detail) Default algorithm is m. -d True or False If it is true, the called function prints the first 10 elements in the sorted list. Default is False, i.e., not to print out the elements. User can type letters with mixing cases, so ignore the case. However, make sure "if DEBUG:" works properly. -n N It specifies number of elements in an initial list. If the input data is not specified using "-i inputFile", list1 will be populated with a randomly generated integer values, and then the contents will be stored in a default input file, called "input.txt". Also, default value of N is 50. It would be more convenient if we implement the following code in a function: for i in range(0, N): list1.append(random.randint(0, N-1)) -i inputFile It specifies the input filename that contain an initial unsorted list. The integer values are put in a row. Note that inputFile should contain ".txt" as a file extension. As specified above, default inputFile is "input.txt". If inputfile exists in a specified place, the values are read into "list1" and "num" is set to the length of "list1". In this case, user's input (i.e., -n num) is ignored. If inputFile doesn't exist, "list1" needs to be populated randomly according to the value in N. -o outFile It specifies the output filename that will contain sorted integer values. The integer values are put in a row. Note that outputFile should contain ".txt" as a file extension. Default output file will be called as "output.txt". (2.2) Note that "-n" option has higher priority than "-i" option if inputFile doesn't exist. On the other hand, "-i" (2.3) The script will be called "mySortTest". Notice that this time we don't have the ".py" extension. (2.4) Add "#!/usr/bin/env python" at the first line of the script so that the script can be run from the commandline. For some examples, we can type the followings: > ./mySortTest ==> For this case, all default values will be used. i.e., -a m -d False -n 50 -i input.txt -o output.txt > ./mySortTest -a q > ./mySortTest -a q -d true > ./mySortTest -a q -d true -n 100 > ./mySortTest -a q -d true -n 100 -i myInput.txt > ./mySortTest -a q -d true -n 100 -i myInput.txt -o myOutput.txt (2.5) All script should be well documented. ========================================== 3. REGULAR EXPRESSION PRACTICE (20 points) ========================================== Translate each of the following English statements into regular expressions: (3.1) A digit at the beginning of the string and a digit at the end of the string (2 points) (3.2) A string that contains only whitespace characters or word characters (2 points) (3.3) A string with no whitespace characters (2 points) (3.4) Regular expression to match words with exactly two vowels occurring anywhere in the word (4 points) (3.5) Write a program that loops through lines of a file or standard input, each line containing a single word, and prints out words that have two vowels next to one another (10 points) ============================== 4. Grading criteria and policy ============================== Please make sure to include the followings at the header of the code. In summary, each script should contain AT LEAST the followings: -------------------------------------------------------------------- #!/usr/bin/env python # Project: 05 # Description: Sorting Algorithms in Python # Program: mySortTest # Input: input.txt # Output: output.txt # Usage: ./mySortTest (followed by various parameters...) # Name: Your name # UT EID: Your EID # Comments (or README): # Describe what you with to grader to know. # e.g., What did you like/dislike about this project? # What was the most challenging in this project? # etc. # # Don't forget to add your solution to the regular expression practice . #---------------------------- # REGULAR EXPRESSION PRACTICE #---------------------------- # (3.1)... # (3.2)... # (3.3)... # (3.4)... # (3.5)... # Your code goes here... if __name__ == '__main__': # Your code goes here... ------------------------------------------------------------ ======= 6. NOTE ======= This project is worth a total of 250 points: (1) 5 * 40 points plus for "mySortTest"; (2) 20 points for regular expression practice; and (3) 30 points for program styles and correctness. We'll discuss details about the project in the class. Submit your script file, "mySortTest", as follows: > turnin --submit hyukcho project05 mySortTest Good luck!