You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

判断海龟位置是否在字典中时结果不符合预期的问题求助

判断海龟位置是否在字典中时结果不符合预期的问题求助

各位大佬好,我最近在用Python的turtle库写代码时遇到了一个奇怪的问题,想请教大家:

我的部分代码如下:

import turtle

#Set up window
turtle.shape("classic")
turtle.turtlesize(2,2,1)
turtle.setup( 500 , 500 )
turtle.Screen().bgcolor("black")
turtle.color("red")
turtle.pencolor("red")
turtle.penup()
window = turtle.Screen()

i = 1
points = {}

points[i] = turtle.pos() 

if turtle.pos() in  points:
    insideDict = True
    i += 1
    points[i] = turtle.pos
else:
    insideDict = False

明明海龟的位置从存入字典后就没有改变,但insideDict的结果却一直是False。我试过用turtle.pos()、turtle.position、turtle.position()还有各种组合的写法,都没能解决这个问题,有没有人能帮我看看问题出在哪呀?

备注:内容来源于stack exchange,提问作者CurlyDLG

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 08:33:04