CSCI 2040 Final Examination
Python程序代写 and name the program files accordingly. 1.Include all your functions here as a single file called ‘py’A polygon can be represented by a a···
You need to write Python programs for the problem below Python程序代写
and name the program files accordingly.
1.Include all your functions here as a single file called ‘py’
A polygon can be represented by a a list of (x,y) pairs, where each pair is a tuple:[(x1,y1), (x2, y2),(x3,y3),..(xn,yn)]. Write a recursive function
def area( polygon):
to compute the area of a polygon in the list polygon. The function should accept a list described above as argument. This can be accomplished by “cutting off” a triangle, using the fact that a triangle with corners (x1,y1), (x2, y2),(x3,y3) has area (x1y2 + x2y3 + x3y1 – x2y1 – y2x3 – y3x1) / 2.
For example, area( [(0,0), (10,0), (10,10)] ) should return 50.0
You can assume all polygon input are convex ones and no degeneracy.
2.Include all your statements here as a single file called ‘py’ Python程序代写
Write a program that read an input text file with filename through command line argument, then prints the number of characters, words, and lines in file. Handle the file inexistence by catching exceptions using trystatement. The error message should be “File filename does not exist!” Only the message need be printed, and program can quit after that. The output of the program should be
Number of characters : XXX
Number of words : YYY
Number of lines : ZZZ
You can assume the user must input additional file argument in command for this question.
3.Include all your functions here as a single file called ‘py’ Python程序代写
A linked list could be developed using a pair of classes. The class node is used to store an individual linked . The list should be created with all the nodes sorted in order of salary as below i.e. the new node will be inserted into the list according to the order of salary in decreasing order:
Complete the implementation of the LinkedList by providing methods for add & testName. testName should return True if found, False otherwise. add should add the new person to the appropriate position in list according to the input salary. So the following statements
list1 = LinkedList() Python程序代写
list1.add( “Mike”, 12000)
list1.add( “John”, 90000)
list1.add( “Shor”, 8000)
list1.display()
should produce this output
John 90000
Mike 12000
Shor 8000
4.Include all your functions here as a single file called ‘py’ Python程序代写
a. Write a function q4_p1() using numpyto solve the equations below. You need to print the solution for (x,y) in the format [x y].
b.Write a function q4_p2() for the question below. You need to print the solution for (x,y) in the format [x y].
Sometimes if we use the direct matrix divide method to get the solution, it may not work if the rank of the matrix is not corresponds with the number of variables. For example, if you try to solve the equation below with numpy.linalg.inv,
In this case, the Python program will crash. To solve such cases, we have to employ more sophisticated numerical solution. Check pinv in numpy.linalg.pinv and write the code for solving the above matrix.
Submission rules Python程序代写
- Please check the output of your program. Even missing a space in your output would not let our test scripts pass your scripts! Examples for each exercise has told you how to output correctly.
- Please name the script files with the exact names specified in this assignment and test all your scripts. Any script that has any syntax error will not be marked.
- Please pack all your script files as a single archive named as
<student-id>_exam.zip
For example, 1155012345_exam.zip, i.e., just replace <student-id> with your own student ID.
- Submit the zip file to our assignment collection box in Blackboard,
No later than 23:59 on Saturday, Dec. 7, 2019
Anyone caught plagiarizing would get 0 score!Python程序代写