Import turtle as turtle
import math
#
class GraphXY:
def __init__(self, xli...
Computers and Technology, 06.04.2021 05:20 tlecuyer
Import turtle as turtle
import math
#
class GraphXY:
def __init__(self, xlist = None, ylist = None):
self.__x = []
self.__y = []
for i in xlist:
self.__x. append(i)
for i in ylist:
self.__y. append(i)
self.__n = len(self.__x)
self.__s = None
self.__t = None
def printpoints(self):
self.__s = turtle. Screen()
self.__t = turtle. Turtle()
self.__t. forward(200)
self.__t. backward(400)
self.__t. home()
self.__t. left(90)
self.__t. forward(200)
self.__t. backward(400)
self.__t. right(90)
self.__t. home()
self.__t. penup()
for i in range(self.__n):
self.__t. goto(self.__x [i], self.__y[i])
self.__t. pendown()
self.__t. write('x')
self.__t. penup()
def finddistances(self):
# write your code to find distances between all city pairs
return d # this function returns 2D matrix
def makeroads(self, d, m):
# write your code to draw lines between points using turtle
return # this function returns nothing
#
#
# following 2 functions are not part of the class
def mindistance(d):
# write your code here to find minimum distances
return m # this function returns 1D list of minimum distances
def showdistance(d):
# write your code to print distances as a table
return # this function returns nothing
#
#
# Tester code starts here
# x-points of cities
xpoints = [-150, -100, -50, 0, 50, 100, 150]
# y-points of cities
ypoints = [150, -150, 0, 100, 50, 100, -50]
# making a graph object from x-points and y-points
g = GraphXY(xpoints, ypoints)
# print the cities on the graph
g. printpoints()
# finding the distance between each city: this will return 2D Matrix like 7x7
d = g. finddistances()
# printing the table of distances between cities
showdistance(d)
# finding the minimum distance between cities (excluding c0 to c0 etc.)
m = mindistance(d)
print("minimum distances are: ", m)
# Draw the lines connecting cities using minimum distances between them
# this function takes 2 inputs. (1) all distances matrix, and (2) minimum distance list
g. makeroads(d, m)
turtle. done()
I want to connect the nearest dots to each other as shown in the picture
Answers: 1
Computers and Technology, 22.06.2019 22:30
What is the most popular genre of video games?
Answers: 1
Computers and Technology, 22.06.2019 23:30
In my email i got a message it says a quick message and in message details on who its from its says nicole and under nicole is [email protected] -
Answers: 1
Computers and Technology, 23.06.2019 12:30
What is the difference between the internet and the world wide web?
Answers: 1
Computers and Technology, 23.06.2019 13:30
Best laptops for college [$100-$500 range]?
Answers: 2
Physics, 19.12.2020 01:20
Biology, 19.12.2020 01:20
Mathematics, 19.12.2020 01:20
History, 19.12.2020 01:20
Mathematics, 19.12.2020 01:20
Mathematics, 19.12.2020 01:20
History, 19.12.2020 01:20
Mathematics, 19.12.2020 01:20
Mathematics, 19.12.2020 01:20
History, 19.12.2020 01:20
Mathematics, 19.12.2020 01:20