Python 乌龟 - 乌龟位置
Python Turtle - Turtle Location
如果乌龟在一组坐标之上,我想让乌龟回到地板上:
像这样:
floor = -323
if turtle above floor:
turtle.goto(floor)
但我不知道 'if'
语句是如何工作的,因为你不能简单地输入 'if turtle above floor'
有什么帮助吗?
假设您的 "floor" 位于 y=-323,您可能会这样做:
floor = -323
if turtle.ycor() > floor:
turtle.sety(floor)
你用 turtle.ycor()
检索海龟的 y 坐标,检查它是否大于 floor
,如果它被设置为等于地板的 y 坐标。
我也会添加海龟 x 的 X 坐标,这样它就不会响应错误。
floor = -323
if turtle.ycor() > floor:
turtle.goto(turtle.xcor(), floor)
如果乌龟在一组坐标之上,我想让乌龟回到地板上:
像这样:
floor = -323
if turtle above floor:
turtle.goto(floor)
但我不知道 'if'
语句是如何工作的,因为你不能简单地输入 'if turtle above floor'
有什么帮助吗?
假设您的 "floor" 位于 y=-323,您可能会这样做:
floor = -323
if turtle.ycor() > floor:
turtle.sety(floor)
你用 turtle.ycor()
检索海龟的 y 坐标,检查它是否大于 floor
,如果它被设置为等于地板的 y 坐标。
我也会添加海龟 x 的 X 坐标,这样它就不会响应错误。
floor = -323
if turtle.ycor() > floor:
turtle.goto(turtle.xcor(), floor)