Question: I Getting Confused By What He's Asking To Do Im New To Coding And I Need Help Desperately. This homework will explore iteration, the string

I Getting Confused By What He's Asking To Do Im New To Coding And I Need Help Desperately.
I Getting Confused By What He's Asking To Do Im New To
Coding And I Need Help Desperately. This homework will explore iteration, the
string module's constants, the idea of subsets, arithmetic operators, and the computation
of area. We will return to Python scripts like in HW1 (foo.py),

This homework will explore iteration, the string module's constants, the idea of subsets, arithmetic operators, and the computation of area. We will return to Python scripts like in HW1 (foo.py), rather than Jupyter notebooks as in HW2 and lab (foo.ipynb). This will allow you to (weakly) test your solutions using our (weak) tester, and it will allow us to autograde your HW (using a strong tester). Therefore, I will provide you with stubbed functions (empty body) and you define the body of these functions. Do not change the name of the Python script (hw3_23sp103.py) since the autograder will be looking for that file. Do not change the name of the functions inside the Python script, since the autograder will be looking for those function names. HW3 syntax constraints Certain Python syntax will be banned in each homework. The tester will clarify what is not allowed. Almost anything we have covered in class so far is allowed (except print). You should not use advanced Python syntax that we have not covered in class. The autograder enforces the same constraints as the tester, so you can find out if your code is legal by first running through the tester. The following syntax is banned for HW3: printing, the replace function in the string module, use of the NumPy module, recursion. HW3 style constraints - each line should contain no more than 80 characters - do not hardcode the test cases into your solutions (this is counterproductive anyway, since the autograder uses different test cases) HW3 problems improveFilename (fn) Write the function inproveFilename that takes a string fn and transforms the string into a legal identifier with only ASCII letters, decimal digits, and undersores. _ is the underscore character. In particular, replace all whitespace characters by underscores, remowe other illegal characters (such as parentheses), and if the string begins with a digit, add a leading underscore in front of this digit (since identifiers cannot begin with a digit). You can use the string module's string constant string . whitespace to identify whitespace characters (such as tabs), atring-ascii_letters to identify ASCII letters, and string.digits to identify digits. The string module's replace function is banned. I am booking for a standard iterative solution bere. See the tester for sample inputs. subsetToBinary (A,B) Write a function subsetToBinary that tabes two lists A and B, each representing a finite set of integers, where A is a subset of B (see below), and returns a string, reptesenting the binary number encoding of the subset A in B (see below). The set is a mathematical model for a collection of things. For example, a set of integers might contain the elements 3 and 5 . The elements of a set have no order (normally you can't talk about the first element of the set) and a set cannot have any duplicate elements. Sets are a very important concept in computer science. A finite set of integers could be represented by a list of integers. (Python has a set type, but we will not be using it in this function.) For example, the list 3,5 could represent the set containing 3 and 5 . This adds an order to the elements of the set, which is not normally present in the set, but this is useful in this exercise. The set A is a subset of auother set B if every element of A also lies in B. For example, the set containing 3 and 5 is a subset of the set containing 2,3,5, and 6. Since we have imposed an order to the elements of B (artificially), we can encode the subect A by a binary number, where the ith digit of the binary number is 1 if the associated element of B is in the subset, and 0 if the associated element of B is not in the subeet. For example, if A is represented by [3,5] and B is represented by [2,3,5,6], then the binary encoding of A is 40110 '. Now you know enough to solve the problem. Note: Python can work with binary numbers (eg., try 10+0b1010 in your interpreter, where the prefix 0b indicates a binary number), but we will not be using this capability bere either, but instead simulating a binary number using a string. Note: this exercise makes it clear that there are 2n subsets of a set of size n (can you see why?). For a bonus, explain why as a comment at the bottom of your function. This is an important insight about subsets. There are exponentially many subsets (so the number of subsets quickly gets out of control). getIthFromEnd (n,k) Write a function getIthFromEnd that taks two nonnegative integers n and k, and returns the kth digit from the end of n. The Oth digit from the end of n is the last digit of n. For example, getIthFromEnd (456,1) should return 5 , If k is too large, pushing past the beginning of n. you should return (imagine that n is padded with as many leading zeroes as you want). No casting to string is allowed to solve this problem. Such a solution will pass the tester, bat will receive no points. Your answer should not involve any strings at intermediate stages, just numbers. signedArea(A,B,C) Write the function signedArea that takes three parameters A, B, and C, representing the three vertices of an oriented triangle, and returns the signed area of the triangle ABC. Each parameter is a tuple of 2 floats, representing a point in 2-space. 2-space is our term for two dimensional space, like the floor of your room, but a really large room. The signed area of the oriented triangle ABC in 2-space is the area of the triangle, but positive if ABC defines a left turn (counterclockwise) and negative if ABC defines a right turn (clockwise). For example, if A=(1,1),B=(3,1),C=(3,2), then the signed area of the triangle ABC is 1.0, and the signed area of the triangle ACB is 1.0. To calculate the signed area of the triangle ABC, use the following facts. The vector between two points P and Q is Q - P (component-wise subtraction: for example, (2,1)(.5,3) is (1.5,7) ). The signed area of the triangle spanned by vectors V=(v0,v1) and W=(w0,w1) is 2v0+w1v1+w2, Another way of thinking of this result: if we let O=(0,0) be the origin in 2 -space, P=(p0,p1) and Q=(q0,q1) be arbitrary points in 2 -space, then the signed area of the triangle OPQ is 2p0+1p+q0. Note: this function allows you to determine whether you are turning left or right as you move around a polygon (how?). This will be useful later in the Graham scan algorithm for computing the convex hull of a polygon. areaPolygon(p)WritethefunctionareaPolygonthattakesalistpoftuples,representingthevertices of a polygon, sorted counterclockwise around the polygon, and returns the area of the polygon. The area of a polygon may be decomposed into the sum of the signed areas of a collection of triangles built by walking around the polygon. In particular, if the polygon vertices moving counterclockwise around the polygon are p0,p1,,pk and if O is the origin (0,0) in 2 -space, then the polygon area is the sum of the signed areas of the triangles Op0p1,Op1p2,,Opkp0. (If you walk around the polygon in the clockwise direction, then the sum of the signed areas will be the negative area of the polygon.) Your code should use the signedArea function you designed above. We will explain why this works in lecture. Note: It turns out that you could replace the origin O by any other fixed point in 2 -space: choosing the origin simplies the computation. def subsetTobinary(A, B) \# ADD CODE HERE, REPLACHNG THE RETUEW pass def getzthfremendth, k)t * ADD CODE HERE, REPLACENG THE RETUEW pass def stgnedAreat, B, C): * ADD CODE HEERE, REELLCING THE RETUPW pass def areapolygon(p)s * ADD CODE HERE, REPLACING THE RETURW pass

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!