这个代码应该根据用户输入使乌龟移动到某个方向有什么问题?
import turtle
myTurtle = turtle.Turtle()
instruction = input()
xCor = myTurtle.position() + 10
yCor = myTurtle.position() - 0
if instruction == "right":
myTurtle.goto(xCor,yCor)
PS:我是初学者所以请不要因为给出一个非常复杂的答案而让我感到沮丧xD
答案 0 :(得分:0)
您的问题是这一行(以及相关的yCor
):
xCor = myTurtle.position() + 10
position()
返回一个包含X&的元组是的,不是数字。您可能想要的是:
import turtle
myTurtle = turtle.Turtle()
instruction = input()
xCor = myTurtle.xcor() + 10
yCor = myTurtle.ycor() - 0
if instruction == 'right':
myTurtle.goto(xCor, yCor)
turtle.done()