Question: python coding In this program, we are playing the game of connect - the - dots. I give you the coordinates for points that you

python coding
In this program, we are playing the game of connect-the-dots. I give you the coordinates for points that you need to connect and you write the code that will connect them into a polygon and draw it. The coordinates of the points you need to connect will be written in a file.
Task 1 drawing a polygon from two lists of coordinates: First, imagine that the point coordinates are split into a list of x-coordinates and another list of corresponding y-coordinates. Like so: x =[3,2.5,5] y =[2,7.3,4] Here, those two lists represent three points: the first point has coordinates (3,2), the second (2.5,7.3), and the third (5,4). We can connect these points with lines and draw them, using our graphics commands. Moreover, we can connect the last point to the first and form a polygon. For example: from graphics import
add the coordinates of the fourth point (3.8,3.7).
add a light green background to the window and set the polygons fill color to light blue. Finally, add your name to appear in the windows title.
Task 2 reading coordinates from the file: Consider a file points1.txt. It has two lines the first contains x-coordinates separated by commas, and the second y-coordinates, also separated by commas. Lets save this file in the same folder we were using before (you can click on it, right-click on the link and click Save as, then find the folder you are working in and save it there). Make sure you save it with the same name and .txt extension. Then the following code will be able to read these coordinates into the x and y lists and then print out coordinates for each point. def main(): fileName = "points1.txt" infile = open(fileName,'r') x=[] y=[] line = infile.readline() for xStr in line.split(","): x.append(float(xStr)) line = infile.readline() for yStr in line.split(","): y.append(float(yStr)) for i in range(len(x)): print(f'point: ({x[i]},{y[i]})') main() Try this code too. Create a new Python file, and save it as p5_2.py. Make sure, its saved in the same folder as all others we used so far. Run it and see if you are getting the coordinates read from the file and printed out. You do not need to submit this part either. But you do need to make sure it works before completing the final task.
my code so far -
def main():
x =[3,2.5,3.8,5]
y =[2,7.3,3.7,4]
p_list=[] #Would be a list of Points. Its empty at first.
p_list.append(Point(x[0], y[0]))
p_list.append(Point(x[1], y[1]))
p_list.append(Point(x[2], y[2]))
p_list.append(Point(x[3], y[3]

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 Programming Questions!