Python 类型错误:'&燃气轮机';在';方法';和';方法';

Python 类型错误:'&燃气轮机';在';方法';和';方法';,python,typeerror,turtle-graphics,python-turtle,Python,Typeerror,Turtle Graphics,Python Turtle,我本来打算尝试做一个海龟比赛,让你选择一个海龟的名字,并尝试能够猜测海龟将赢得比赛我有一些问题,到目前为止,但现在我无法找出哪里出了问题,所以有人能告诉我为什么会出现这个错误代码吗?(我不熟悉堆栈溢出) @RandomDavis在他们的评论(+1)中涵盖了您的主要错误,但还有其他问题。例如,speed()和random.randint(1,5)本身不是操作。此外,当您必须以两种不同的方式导入turtle和random时,您也会遇到麻烦。让我们将代码重新编写成有效的程序: from turtle

我本来打算尝试做一个海龟比赛,让你选择一个海龟的名字,并尝试能够猜测海龟将赢得比赛我有一些问题,到目前为止,但现在我无法找出哪里出了问题,所以有人能告诉我为什么会出现这个错误代码吗?(我不熟悉堆栈溢出)


@RandomDavis在他们的评论(+1)中涵盖了您的主要错误,但还有其他问题。例如,
speed()
random.randint(1,5)
本身不是操作。此外,当您必须以两种不同的方式导入turtle和random时,您也会遇到麻烦。让我们将代码重新编写成有效的程序:

from turtle import Screen, Turtle
from random import randint

screen = Screen()

marker = Turtle()
marker.speed('fastest')
marker.penup()
marker.goto(-140, 140)

for number in range(15):
    marker.write(number, align="center")
    marker.right(90)

    for _ in range(8):
        marker.penup()
        marker.forward(10)
        marker.pendown()
        marker.forward(10)

    marker.penup()
    marker.backward(160)
    marker.left(90)
    marker.forward(20)

marker.hideturtle()

A = Turtle()
A.shape('turtle')
A.color('red')
A.penup()
A.goto(-160, 100)

B = Turtle()
B.shape('turtle')
B.color('red')
B.penup()
B.goto(-160, 70)

C = Turtle()
C.shape('turtle')
C.color('red')
C.penup()
C.goto(-160, 40)

D = Turtle()
D.shape('turtle')
D.color('red')
D.penup()
D.goto(-160, 10)

for _ in range(100):
    A.forward(randint(1, 5))
    B.forward(randint(1, 5))
    C.forward(randint(1, 5))
    D.forward(randint(1, 5))

if A.xcor() > B.xcor() and A.xcor() > C.xcor() and A.xcor() > D.xcor():
    print("The turtle you picked you picked won the race!")

screen.mainloop()

@RandomDavis在他们的评论(+1)中涵盖了您的主要错误,但还有其他问题。例如,
speed()
random.randint(1,5)
本身不是操作。此外,当您必须以两种不同的方式导入turtle和random时,您也会遇到麻烦。让我们将代码重新编写成有效的程序:

from turtle import Screen, Turtle
from random import randint

screen = Screen()

marker = Turtle()
marker.speed('fastest')
marker.penup()
marker.goto(-140, 140)

for number in range(15):
    marker.write(number, align="center")
    marker.right(90)

    for _ in range(8):
        marker.penup()
        marker.forward(10)
        marker.pendown()
        marker.forward(10)

    marker.penup()
    marker.backward(160)
    marker.left(90)
    marker.forward(20)

marker.hideturtle()

A = Turtle()
A.shape('turtle')
A.color('red')
A.penup()
A.goto(-160, 100)

B = Turtle()
B.shape('turtle')
B.color('red')
B.penup()
B.goto(-160, 70)

C = Turtle()
C.shape('turtle')
C.color('red')
C.penup()
C.goto(-160, 40)

D = Turtle()
D.shape('turtle')
D.color('red')
D.penup()
D.goto(-160, 10)

for _ in range(100):
    A.forward(randint(1, 5))
    B.forward(randint(1, 5))
    C.forward(randint(1, 5))
    D.forward(randint(1, 5))

if A.xcor() > B.xcor() and A.xcor() > C.xcor() and A.xcor() > D.xcor():
    print("The turtle you picked you picked won the race!")

screen.mainloop()

海龟的
xcor
属性。海龟对象不是类变量, 但是类函数,因此需要使用
()
调用它以获取返回值

更改:

if A.xcor > B.xcor and A.xcor > C.xcor and A.xcor > D.xcor():
  print("Wow the turtle you picked you picked wow the race!")
致:

我更倾向于使用内置函数:

if all(A.xcor() > t.xcor() for t in [B, C, D]):
  print("Wow the turtle you picked you picked wow the race!")
编辑:


Turtle
对象的
xcor
属性不是类函数,而是实例方法cdlane


turtle.turtle
对象的
xcor
属性不是类变量, 但是类函数,因此需要使用
()
调用它以获取返回值

更改:

if A.xcor > B.xcor and A.xcor > C.xcor and A.xcor > D.xcor():
  print("Wow the turtle you picked you picked wow the race!")
致:

我更倾向于使用内置函数:

if all(A.xcor() > t.xcor() for t in [B, C, D]):
  print("Wow the turtle you picked you picked wow the race!")
编辑:


Turtle
对象的
xcor
属性不是类函数,而是实例方法cdlane


Turtle
对象的
xcor
属性不是一个类函数,而是一个实例方法。@cdlane有这样一个类函数吗?@AnnZen称为a。
Turtle
对象的
xcor
属性不是一个类函数,而是一个实例方法。@cdlane有这样一个类吗那么函数?@AnnZen这将被称为a。如果答案解决了您的问题,请用复选标记标记答案,或者评论他们为什么没有解决您的问题。如果答案解决了您的问题,请用复选标记答案,或者评论他们为什么没有解决您的问题。