-1
Я получаю эту ошибку:Проблемы с черепахой
Traceback (most recent call last):
File "C:/Users/jadyn/Documents/file type computer science.py", line 1, in <module>
from turtle import Screen, Turtle
File "C:/Users/jadyn/Documents\turtle.py", line 4, in <module>
t = turtle.Pen()
AttributeError: 'module' object has no attribute 'Pen'
Когда я пытаюсь запустить этот
from turtle import Screen, Turtle
from random import randint
def getDistance(routeName, startingPoint, pointA, pointB, pointC, endingPoint):
global routes
route = 0
route += getDistance(startingPoint, pointA)
route += getDistance(pointA, pointB)
route += getDistance(pointB, pointC)
route += getDistance(pointC, endingPoint)
routes += [[routeName, route, startingPoint, pointA, pointB, pointC, endingPoint]]
points = []
def Distance(pointOne, pointTwo):
lengthOne = pointOne[0] - pointTwo[0]
lengthTwo = pointOne[1] - pointTwo[1]
lengthOneSquared = lengthOne * lengthOne
lengthTwoSquared = lengthTwo * lengthTwo
lengthThreeSquared = lengthOneSquared + lengthTwoSquared
lengthThree = lengthThreeSquared ** 0.5
return lengthThree
for i in range(5):
randomOne = randint(-24,25)
randomTwo = randint(-24,25)
points += [[randomOne,randomTwo]]
startingPoint = points[randint(0,4)]
points.remove(startingPoint)
endingPoint = points[randint(0,3)]
points.remove(endingPoint)
routes = []
getDistance("Route One", startingPoint, points[0], points[1], points[2], endingPoint)
getDistance("Route Two", startingPoint, points[1], points[2], points[0], endingPoint)
getDistance("Route Three", startingPoint, points[2], points[0], points[1], endingPoint)
getDistance("Route Four", startingPoint, points[0], points[2], points[1], endingPoint)
getDistance("Route Five", startingPoint, points[1], points[0], points[2], endingPoint)
getDistance("Route Six", startingPoint, points[2], points[1], points[0], endingPoint)
routesSorted = sorted(routes,key=lambda l:l[1])
print(routesSorted[0])
scale = 15
window = Screen()
cursor = Turtle()
cursor.penup()
cursor.goto(routesSorted[0][2][0] * scale, routesSorted[0][2][1] * scale)
cursor.pendown()
for i in range(3):
cursor.goto(routesSorted[0][i+3][0] * scale, routesSorted[0][i+3][1] * scale)
cursor.goto(routesSorted[0][6][0] * scale,routesSorted[0][6][1] * scale)
window.mainloop()
вы можете сказать мне, почему я попробовал несколько раз и до сих пор не понимаю, почему это происходит !
Это, безусловно, второй. 'Pen' является допустимым атрибутом стандартного модуля' turtle' - это псевдоним класса 'Turtle'. (есть и строчный метод «pen», и это может быть то, что OP фактически должен использовать, но это не является причиной этого конкретного сообщения об ошибке) – Kevin
У меня нет файла с именем turtle.py –
я тоже не могу найти фактическая строка –