为什么这一点我不能得到X?

2024-10-01 09:20:41 发布

您现在位置:Python中文网/ 问答频道 /正文

    def drawAllStars(window,numOfStars):
    starlist=list()
    for x in range(numOfStars):
        cntrx = random.randrange(1000)
        cntry= random.randrange(1000)
        cntr = graphics.Point(cntrx, cntry)
        drawstars(cntrx, cntry, 5, "black", window)
        starlist.append(cntr)
    print(starlist)
    return starlist

def getDistance(point1,point2):
    a= point1.getX()
    b= point2.getX()
    c= point1.getY()
    d= point2.getY()
    distance=  math.sqrt((b-a)**2 + ((d-c)**2))
    return distance

def balloonStarCollide(balloon, star):
    point1 = balloon.getCenter()
    point2= star
    distance= getDistance(point1, point2)
    if distance <= 30:
        return True
    else:
        return False

def checkForStarCollision(balloon, stars):
    for star in stars:
       collide = balloonStarCollide(balloon, stars)
       if collide == True:
           return True

所以我画了一张星星的名单,列出了它们的中心点。然后我得到了一个函数,它可以得到给定星体的中心差,然后将其与用户控制的圆的中心进行比较。程序中断了getDistance函数,声称getX对于“list”对象是不可能的。在


Tags: truereturndefwindowstardistancestarsballoon
1条回答
网友
1楼 · 发布于 2024-10-01 09:20:41

您在checkForStarCollision中有一个打字错误。排队

collide = balloonStarCollide(balloon, stars)

应该是

^{pr2}$

假设stars是一个列表,这将解释您的错误消息。在

相关问题 更多 >