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 connectthedots. 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 drawing a polygon from two lists of coordinates: First, imagine that the point coordinates are split into a list of xcoordinates and another list of corresponding ycoordinates. Like so: x y Here, those two lists represent three points: the first point has coordinates the second and the third 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
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 reading coordinates from the file: Consider a file pointstxt It has two lines the first contains xcoordinates separated by commas, and the second ycoordinates, also separated by commas. Lets save this file in the same folder we were using before you can click on it rightclick 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 "pointstxt infile openfileNamer x y line infile.readline for xStr in line.split: xappendfloatxStr line infile.readline for yStr in line.split: yappendfloatyStr for i in rangelenx: printfpoint: xiyi main Try this code too. Create a new Python file, and save it as ppy 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
y
plist #Would be a list of Points. Its empty at first.
plist.appendPointx y
plist.appendPointx y
plist.appendPointx y
plist.appendPointx y
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
