Submit one Jupyter notebook named as yourLastName_HW02 with appropriate code cell to solve thefollowing questions. Make sure that the question is included in your notebook as a markdown cell aboveyour answer. You must use only the basic Python and no external module or library is allowed otherthan math or os modules. Include any specific direction/instruction to run your script in comments. Forall questions, the main functionality of your Python script should be implemented as a Python function.Note: if you want to include your script as separate .py files, you may submit all source files with aJupyter notebook in a zipped file (compressed). In the notebook, inside the code cell of a question, write%run Qx. Where x is the number of the question.Undergraduate: Each question worth 15 points.Graduate: Each question worth 10 points.Q1) Write a Python script to mimic a trivial text editor in search and replace functionality. Your programaccepts a text file named test.txt and, using a menu-like, can either search for all occurrences of agiven string or replace one or all occurrences of a given string. Your program should write back on theoriginal text (update it) when replace option is selected. No need to submit your test.txt you used fordebugging. The grader will use his own test.txt.Q2) Write a Python script that finds the largest difference between elements of a given list. For example,the largest difference in [2, 5, -3, 4, 7, 9] is 12. The list is entered as one single comma-separated string.Q3) Write a Python script that simplifies a given string. It removes any tabs, newline, or multiple whitespaces. For example: the string This is a nice day
will be simplified to This is a niceday. The string should be read from a text file called test2.txt. The string could be on one or morelines. No need to submit your test2.txt. We will use our own test2.txt to grade your program.Q4) Write a Python script that contains a recursive function to calculate the nth Fibonacci, where f(n) =1, n=1,2 and f(n) = f(n-1)+f(n-2), n>2. Your program will accept the value of n.Q5) Write a Python script that contains your own implementation of the functional tool filter. Yourfunction should be named as myFilter with header (foo, iterableObject). For simplicity, the iterableobject could be a numerical list, set, or a tuple. Your program accepts it as one single line with theappropriate brackets/braces/parenthesis to denote the type of the object. For example, if the userwould like to enter a list, s/he will type in something like: [2, 4, 2, 9].Q6) Write a Python script that contains a function called foo that accepts a variable number ofnumerical parameters and returns these numbers sorted (in ascending order) and saved in a list. We willupdate your code with our invocation to your function.Q7) Write a Python script to accept a text file called test3.txt and returns some statistics about it.Statistics include: #lines, #words, #characters, #printable special characters (anything that is notalphanumeric).Graduate Students OnlyQ8) Write a Python script that contains a function lensort to sort a list of strings based on length. Theuser will enter the list of strings as one comma-separated line.Q9) Write a Python script that contains a function triplets that takes a number n as argument andreturns a list of triplets such that the sum of the first two elements of the triplet equals the thirdelement using numbers below n. Please note that (a, b, c) and (b, a, c) represent the same triplet.Example: t r i p l e t s ( 5 ) produces [ ( 1 , 1 , 2 ) , ( 1 , 2 , 3 ) , ( 1 , 3 , 4 ) , ( 2 , 2 , 4 ) ]Q10) Write a Python script that contains a function to calculate the angle between 3 given 3d points.Each point is accepted as a comma-separated string as x, y, x and you process it.Bonus Question: (10 points)Q11) Write a Python program to explore a given directory in the local machine. Your program accepts apath to a directory from test4.txt and does the following (in a menu-like): search for a file, list all subdirectories,list all files with a given extension, remove a given file, and show all files sorted by date/timemodified. test4.txt will have a single line that contains the full path of the directory we are interestedin. For example: the only line in the text could be c:Program files to denote to the program filesdirectory in c drive. You can use os module.Due date: 02/21/2019 at 11:59PMHow to submitThrough blackboard. No hard copy is accepted. The system will close after 11:59PM and you willnot be able to turn it in. No late submission is accepted unless you receive instructors approvalno less than two days before the due date.
CS3753/5163
[Solved] Homework Assignment #2 CS 3753/5163
$25
File Name: Homework_Assignment_#2_CS_3753/5163.zip
File Size: 329.7 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.