-1
ich diesen Fehler:Probleme mit Schildkröte
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'
Wenn ich versuche, dies zu laufen
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()
können Sie mir sagen, warum ich einige Zeit versucht haben und immer noch nicht verstehen, warum dies geschieht !
Es ist definitiv der zweite. 'Pen' ist ein gültiges Attribut des Standardmoduls' turtle' - es ist ein Alias der Klasse 'Turtle'. (Es gibt auch eine Kleinschrift 'Stift'-Methode, und das könnte sein, was OP eigentlich verwenden sollte, aber es ist nicht die Ursache dieser spezifischen Fehlermeldung) – Kevin
Ich habe keine Datei namens turtle.py –
Ich kann auch nicht finden actual line –